只是制作一个小程序来启动 c++,编译器说有一个没有 if 的 else 来引用 main 中的 while 循环,但显然不是这样,我不明白为什么。如果我删除 while 循环,它工作正常。
#include <iostream>
using namespace std;
int number;
int arithmetic(int num)
{
if(num > 20)
num = num * 5;
else
num = 0;
return (num);
}
int main()
{
int wait;
cout << "I will take any number providing it is higher than twenty" << endl;
cout << "and I will multiply it by 5. I shall then print every number" << endl;
cout << "from that number backwards and say goodbye." << endl;
cout << "Now please give me your number: " << endl;
cin >> number;
int newnum = arithmetic(number);
if (newnum != 0)
cout << "Thank you for the number, your new number is" << newnum << endl;
while(newnum > 0){
cout << newnum;
--newnum;
}
cout << "bye";
else
cout << "The number you entered is not greater than twenty";
cin >> wait;
return 0;
}