一切都像我想要的那样工作,但唯一的是,当我执行这个文件时,它会在行尾产生一些随机数,我认为这是不正常的,我知道什么是错的这个代码,任何人都可以看看这个代码,并告诉我什么是错在C++执行后的随机数
#include "stdafx.h"
#include <iostream>
#include <Windows.h>
using namespace std;
void message();
int choose1(char);
int choose2(char);
int choose3(char);
int main()
{
message();
int inputA, inputB, inputC;
cout<<"A little girl kicks a soccer ball. It goes 10 feet and comes back to her. How is this possible?"<<endl;
cout<<"---------------------------------------"<<endl;
cout<<"1. Because the ball has air in it. "<<endl;
cout<<"2. Because the ball went up. "<<endl;
cout<<"3. Because of the gravity."<<endl;
cin>>inputA;
cout<<choose1(inputA)<<endl;
system("PAUSE");
system("cls");
cout<<"How can a man go eight days without sleep?"<<endl;
cout<<"1. Because he is death. "<<endl;
cout<<"2. Because he slept at night. "<<endl;
cout<<"3. Because he is not born yet. "<<endl;
cin>>inputB;
cout<<choose2(inputB)<<endl;
system("PAUSE");
system("cls");
cout<<"What can you never eat for breakfast??"<<endl;
cout<<"1. Breakfast. "<<endl;
cout<<"2. Dinner. "<<endl;
cout<<"3. Lunch. "<<endl;
cin>>inputC;
cout<<choose3(inputC)<<endl;
system("PAUSE");
system("cls");
cout<<"\n\n\n\nThank you for playing this simple game K,Thsuyipa Yimchunger\n\n\n\n"<<endl;
system("PAUSE");
return 0;
}
void message(){
system("color a");
cout<<"===================================================="<<endl;
cout<<"===================================================="<<endl;
cout<<"Hi welcome to this simple math book"<<endl;
cout<<"here we will ask you some simple question and"<<endl;
cout<<"all you have to do is just press the number which \nyou think is the right answer"<<endl;
cout<<"===================================================="<<endl;
cout<<"===================================================="<<endl;
cout<<"===================================================="<<endl;
}
int choose1(char input){
switch(input){
case 1:
cout<<"The answer is wrong.... Better luck next time"<<endl;
break;
case 2:
cout<<"The answer is wrong.... Better luck next time"<<endl;
break;
case 3:
cout<<"The answer is RIGHT.... Because she kick the ball and gravity pull it down ;) "<<endl;
break;
default:
cout<<"You've entered a wrong digit"<<endl;
return 1; //Same thing with a boolean. If it doesn't have a matching case, return 1 to note that is was a failure.
}
}
int choose2(char input){
switch(input){
case 1:
cout<<"The answer is wrong.... Better luck next time"<<endl;
break;
case 2:
cout<<"The answer is RIGHT.... Because he slept during the night time ;)"<<endl;
break;
case 3:
cout<<"The answer is wrong.... Better luck next time "<<endl;
break;
default:
cout<<"You've entered a wrong digit"<<endl;
return 1; //Same thing with a boolean. If it doesn't have a matching case, return 1 to note that is was a failure.
}
}
int choose3(char input){
switch(input){
case 1:
cout<<"The answer is wrong.... Better luck next time"<<endl;
break;
case 2:
cout<<"The answer is RIGHT.... ;) "<<endl;
break;
case 3:
cout<<"The answer is wrong.... Better luck next time"<<endl;
break;
default:
cout<<"You've entered a wrong digit"<<endl;
return 1; //Same thing with a boolean. If it doesn't have a matching case, return 1 to note that is was a failure.
}
}
该行?哪条线?这里有很多线条,我敢打赌,99%的线条与你的问题无关。 – tadman
这里的随机数是屏幕截图http://i.imgur.com/nnFhMaE.png – user8286839
注意'return'语句在你的选择函数中。这是非法的代码。具有非'空号'返回类型的函数必须在所有路径上返回一个值。 – user4581301