我是 C++ 新手。我的第一个目标是让一个成功的计算器程序成为 Win32 控制台应用程序,但我不断收到错误消息。我把这段代码:
cout << "Do you want to continue? N/Y" << endl;
cin >> ny;
if (ny == "Y") goto start;
if (ny == "N") goto end;
但无论哪种方式,它都会继续结束。
这是“结束”的代码:
// End - Properties
system("cls");
system("title Basic Calculator - End");
system("color 4F");
// End - Start
ny == "0";
cout << "Are you sure you want to end? N/Y" << endl;
cin >> ny;
if (ny == "N") goto start;
cin.get();
return 0();
最后它也总是结束程序。
如果您发现错误,请告诉我。
-丹麦胡梅尔
完整代码:
#include <iostream>
using namespace std;
int main()
{
start:
// Program - Properties
system("cls");
system("title Basic Calculator - Main Screen");
system("color 1F");
// Program - Setup
int input;
int x;
int y;
char ny [10];
// Program - Start
cout << "Please choose an operation from the following." << endl << endl;
cout << "1. Addition \n2. Subtraction \n3. Multiplication \n4. Division" <<endl << endl;
cin >> input;
if (input = 1) goto addition;
if (input = 2) goto subtraction;
if (input = 3) goto multiplication;
if (input = 4) goto division;
cin.get();
addition:
// Addition - Properties
system("cls");
system("title Basic Calculator - Addition");
system("color 2F");
// Addition - Start
cout << "Please input your first number." << endl;
cin >> x;
cout <<endl << "Please input your second number."<< endl << endl;
cin >> y;
cout <<endl <<endl << "The answer is " << x+y << ".\a" << endl << endl;
cout << "Do you want to continue? N/Y" << endl;
cin >> ny;
if (ny == "Y") goto start;
if (ny == "N") goto end;
cin.get();
subtraction:
multiplication:
division:
end:
// End - Properties
system("cls");
system("title Basic Calculator - End");
system("color 4F");
// End - Start
ny == "0";
cout << "Are you sure you want to end? N/Y" << endl;
cin >> ny;
if (ny == "N") goto start;
cin.get();
return 0();
}