跳过初学者C++功能:没有错误
Beginner C++ Function skipped: No errors
我不知道这里发生了什么。 我没有收到任何错误,程序点击第一个函数,然后跳过返回 0。 这是我正在做的练习。 用户将在汽水机中输入一个数字,然后他们会收到他们选择的项目。 任何帮助将不胜感激!
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
void Menu()
{
cout << "===========================" << endl;
cout << "========SODA MACHINE=======" << endl;
cout << "===========================" << endl;
cout << "Pick a soda... " << endl;
cout << "[1] Coca-Cola" << endl;
cout << "[2] Diet Coca-Cola" << endl;
cout << "[3] MUG Root Beer" << endl;
cout << "[4] Sprite" << endl;
}
int processSelection()
{
int selection;
cin >> selection;
cout << "This function was called." << endl;
return selection;
}
void dropSoda()
{
int myselection;
myselection = processSelection();
switch (myselection)
{
case 1:
cout << "Your can of Coca-Cola drops into the bin at the bottom of the machine." << endl;
break;
case 2:
cout << "Your can of Diet Coca-Cola drops into the bin at the bottom of the machine." << endl;
break;
case 3:
cout << "Your can of MUG Root Beer drops into the bin at the bottom of the machine." << endl;
break;
case 4:
cout << "Your can of Sprite drops into the bin at the bottom of the machine." << endl;
break;
default:
cout << "INVALID SELECTION." << endl;
break;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
Menu();
int processSelection();
void dropSoda();
return 0;
}
int processSelection();
这是一个函数声明。它告诉编译器有一个函数processSelection
不带参数并返回int
- 但编译器已经知道这一点。
要调用该函数,您需要编写:
processSelection();
dropSoda
也是如此.
您的主要函数是声明函数,而不是调用它们。
int _tmain(int argc, _TCHAR* argv[])
{
Menu(); // menu called
// declare a function `processSelection` taking no arguments and returning an int
int processSelection();
// again, functoin declaration
void dropSoda();
return 0;
}
若要修复,请以与调用Menu()
相同的方式调用这两个函数
int _tmain(int argc, _TCHAR* argv[])
{
Menu();
processSelection();
dropSoda();
return 0;
}
相关文章:
- 我的代码中有错误吗?使用BGI图形的C++代码对我不起作用
- 是否有任何C++功能可以对地图进行排序?
- 在气泡排序程序中未声明错误功能
- 我的代码中有错误,未声明的标识符
- C++ LeetCode #377 的 DP 解决方案中,此代码是否有错误?
- 试图建立银行管理系统,但有错误
- 我试图创建临时对象的方式有错误吗
- 我的随机生成器是否不工作,或者我决定人/骨架是否击中对手的方式是否有错误
- 我有模板功能.通过使用函数std::for_each,用这个容器中的最大数字替换每个正数
- 我在OpenCV中有错误的"approxPolyDP(ROI_Vertices, ROI_Poly, 1.0, true)"
- C++插入排序错误功能不起作用
- 我在这个 C++ 代码上有错误吗?
- 是视觉C++优化器错误还是我的代码中有错误?
- "hello triangle"未显示。是否有某些功能未正确使用?
- 为什么一个简单的C++程序会有错误的结果?是 #define 引起的吗?
- 对此有错误
- 是否有任何功能可以通过按不同的按钮来更改操作
- C :数据文件有错误:预期的无限制ID
- 一个带有参数的程序,为什么此程序有错误的答案
- 融合有尾部功能吗?