我是C++的新手,我真的被困在這個問題: 當用戶輸入2個數字EX:1和2比代碼必須找出是否第一個數字是否與第一個數字相同,問題是該代碼沒有將文本帶來的真或假作爲數字:/ (0 = false 1 = true)如何讓我的功能帶回真或假
代碼在這裏:
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
bool GraterFunct(int num1, int num2);
int main(int argc, char** argv)
{
std::cout <<" \n Hello there! This is a test to test how good you are with math. \n ";
std::cout <<" Now enter G or L (Grater, less) to know if a number is grater or less than the number you choose \n ";
char answer [1];
std::cin >> answer;
if(answer == "G" || "g")
{
int number1;
int number2;
std::cout << "You selected: Grater than, \n";
std::cout << "Now type 2 numbers and see which one is grater than the other one. \n" << std::endl;
std::cin >> number1;
std::cout << "Your first number: " << number1 << std::endl;
std::cout << "Select your second number \n";
std::cin >> number2;
std::cout << "The answer is: " << GraterFunct(number1, number2);
}
return 0;
}
bool GraterFunct(int num1, int num2)
{
if(num1 >= num2)
{
{
return true;
}
}
else
{
if(num2 >= num1)
{
return false;
}
}
}
請幫忙!提前致謝!
的http://stackoverflow.com/questions/29383 – us2012
重複它的拼寫爲 「大於」 –
縮短:'布爾GraterFunct(INT NUM1,INT NUM2){返回NUM1> = NUM1 ; }' – deepmax