我想要一个名为“userPrompt”的函数,并要求用户输入一个名为“choose”的整数值,以便我可以使用switch语句。Switch Statement - 嵌套函数 - C++
但它没有工作它说:“选择”未申报。
我想它会首先启动主函数,并在其中第一个命令将初始化userPrompt函数。那么感谢userPrompt我会有一个选择值,以便交换机可以工作。
那么这段代码有什么问题?
如何使用嵌套函数?(我希望它被称为像)
是我的代码的顺序错了吗?
任何帮助将不胜感激。
userPrompt(){
int choose;
cout << " Please Choose An Option : " << endl;
cout << " Type 1 to Add new grades : " << endl;
cout << " Type 2 to Calculate the average grades : " << endl;
cout << " Type 3 to Calculate the total grades : " << endl;
cout << " Type 4 to Exit : " << endl;
cin >> choose;
}
int main()
{
userPrompt();
switch(choose){
case 1
getGrade();
userPrompt();
break;
case 2
int average;
getGrade();
average = total/counter;
cout << average;
break;
case 3
getGrade();
cout << total;
break;
case 4
cout << "Thanks for Trying" << endl;
return 0;
system("pause");
break;
default
cout << "Please Choose A Valid Option ! : " << endl;
validOption();
}
}
'choose'仅宣布在本地'userPrompt()'你需要一个'返回'语句或输出参数,将值传递给'main()'中的另一个变量。代码中有更多的语法错误。 – 2015-03-25 07:59:35
谢谢你的回答,我在C++上也是新手,在编程方面也是新的。它会越来越好,我希望:) 我会解决它的。谢谢。 – Recomer 2015-03-25 08:12:45