组合2个函数时Xcode出错
Error in Xcode while combining 2 functions
我的家庭作业几乎不需要帮助。这是一个项目,根据我必须结合两个程序,用户可以选择他想运行的程序;我正在尝试使用IFELSE语句。当分别运行这些程序时,它们运行良好。Xcode在尝试运行第一个程序和函数一时给了我一个问题。你们能帮我吗。?感谢
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;
int main()
{
int x;
cout << "Hello Welcome to my Game Menu. Please make selection from following criteria" <<endl;
cout << "Please press 1 if you would like to play The Guessing Game"<<endl;
cout << "Please press 2 if you would like to play The Math Game"<<endl;
cin >>x;
if ( x == 1)
{
cout << "Welcome to Guessing Game" <<endl;
//declare the variables
int num; //variable to store the random
//number
int guess; //variable to store the number
//guessed by the user
bool isGuessed; //boolean variable to control
//the loop
srand(time(NULL)); //Line 1
num = rand() % 100; //Line 2
isGuessed = false; //Line 3
while (!isGuessed) //Line 4
{ //Line 5
cout << "Enter an integer greater"
<< " than or equal to 0 and "
<< "less than 100: "; //Line 6
cin >> guess; //Line 7
cout << endl; //Line 8
if (guess == num) //Line 9
{ //Line 10
cout << "You guessed the correct "
<< "number." << endl; //Line 11
isGuessed = true; //Line 12
} //Line 13
else if (guess < num) //Line 14
cout << "Your guess is lower than the "
<< "number.n Guess again!"
<< endl; //Line 15
else //Line 16
cout << "Your guess is higher than "
<< "the number.n Guess again!"
<< endl; //Line 17
} //end while //Line 18
}
else if ( x == 2) {
cout <<"Welcome to Math Game " <<endl;
double a,b,x,y,z,sum;
string name;
cout << "Please enter your name... ";
cin>> name;
cout<<endl;
cout << " WELCOME TO MATH MIND TRICKS " <<name <<endl;
cout<< "I will read your mind." <<endl;
cout<< "We will choose five , five digit numbers together" <<endl;
cout<< "but i will be able to give you the sum, just after the first one" <<endl;
cout<<endl;
cout<< "What is your first five digit number?"<<endl;
cin>> x;
cout<<endl;
cout<< " The sum is going to be " << 199998+x <<endl;
cout<< "Please enter a second number" <<endl;
cin>> y;
cout<<endl;
a= 99999-y;
cout<< " OK, im going to choose " <<a <<endl;
cout<< " Please enter your last five digit number" <<endl;
cin>> z;
b= 99999-z;
cout<< " OK, im going to choose " <<b <<endl;
cout<<endl;
sum = a+b+x+y+z;
cout<< " The sum of our five numbers is " <<sum <<endl;
cout<<endl;
cout <<"Impressed? :)" <<endl;
}
return 0;
}
time()返回一个NSUInteger
,并且在64位OSX平台上
- NSUInteger定义为无符号长,并且
- unsigned long是一个64位无符号整数
- int是一个32位整数
因此,int是一个比NSUInteger"小"的数据类型,因此编译器发出警告。
另请参阅"基础数据类型参考"中的NSUInteger:
构建32位应用程序时,NSUInteger是一个32位无符号整数。64位应用程序将NSUInteger视为64位无符号整数。
要修复编译器警告,您可以将本地计数变量声明为
NSUInteger count;
或者(如果你确信你的数组永远不会包含超过2^31-1个元素!),添加一个显式强制转换:
srand((int)time(NULL));
相关文章:
- 访问者访问变体并返回不同类型时出错
- 在Linux for Windows上编译C++代码时出错
- 读取文件的最后一行并输入到链接列表时出错
- 重载操作程序时出错>>用于类中的字符串 memebr
- 调用专用模板时出错"no matching function for call to [...]"
- C++-试图将函数指针推回到另一个CPP文件中的矢量时出错
- LINK 尝试使用 OpenSSL evp aes 256 c++ 时出错
- 在Google Kick start中提交时出错
- 在c++中访问int到类对象的映射时出错
- ld:bind_at_load和-bitcode_bundle(Xcode设置ENABLE_bitcode=YES)不能
- 分段错误当我试图运行程序时出错
- AddInstanceForFactory 和 HALC_ShellDriverPlugIn SDL2 与 Xcode 配合使用时出错?
- 尝试使用全局变量时使用 Xcode C++时出错
- ncurses.h库中的initscr()函数使用xcode时出错
- 组合2个函数时Xcode出错
- 在Xcode中传递指针时出错,但在窗口上的代码块中有效
- 代码在xcode中运行良好,但在命令行中出错
- 在XCode/Clang中使用std::shared_ptr实例化std::map出错
- xcode中的c++:在main中调用自定义对象中的任何(!!!!)方法时出错
- 使用 XCode 在 C++ 中接受函数和写入和读取方法时出错