Я новичок в 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();
И в конце концов, это также всегда заканчивает программу.
Если вы обнаружили ошибку, пожалуйста, дайте мне знать.
-Danish Humair
Полный код:
#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();
}
Вы определенно должны заменить эти 'goto's. – chris
и разместите свои ошибки – billz
У меня только что было общее воспоминание Apple BASIC. – WhozCraig