这段代码只需要一个数字,将它加到另一个数字上,然后将结果打印出来。它还说明了数字是高还是低。这一切都在一个bool
函数中完成:
#include <iostream>
using namespace std;
bool addition(int num, int num2, int total);
int main()
{
int num, num2,total;
cout << "enter a number"<< endl;
cin >> num;
cout<< "enter another number" << endl;
cin >> num2;
addition(num, num2, total);
{
cout <<"the first number is:" << num<< " the second number is: "<< num2 << endl;
cout << "the total is: " << total << endl;
if (1) {
cout << "its low" ;
} else {
cout << "its high";
}
cout << endl;
}
}
bool addition (int num, int num2, int total) {
//total = 0;
total = num + num2;
if (total >= 10){
return 1;
} else {
return -1;
}
}
问题是这个程序总是说数字很低,总数总是 32767。我不知道为什么。