I'm getting 2 C2360 error's on line 53 and 2 more C2360 error's on line 76 , both saying that the initialization of 'x' and 'y' is skipped by 'case' label.
I don't need help finishing it as i want to learn that on my own but i can't seem to find out how to fix the C2350 errors, either advice on coding better by someone with more experience or just a solution to the C2360 would be greatly appreciated.
#include <iostream>
usingnamespace std;
int menuChoice;
char repeatSum;
float product;
int main()
{
do
{
cout << "Welcome to the best calculator in the world!\n\n";
cout << "Pick the number that corresponds to the \n";
cout << "type of mathematical operation you want.\n\n";
cout << "1. Addition!\n";
cout << "2. Subtraction!\n";
cout << "3. Division!\n";
cout << "4. Multiplication!\n";
cout << "5. Close the program!\n";
cout << endl << endl;
cin >> menuChoice;
cout << endl << endl;
switch (menuChoice)
{
case 1:
int sum, difference, x = 0, y = 0;
cout << "Pick your first number you wish to add with another one: ";
cin >> x;
cout << "Pick the second number you wish to add with the first number: ";
cin >> y;
sum = x + y;
cout << endl << endl;
cout << "The sum of " << x << " and " << y << " is " << sum << endl << endl;
cout << "Press Y if you want to return to the ";
cout << "main menu, Press N if you want to close the program: ";
cin >> repeatSum;
break;
case 2:
{
int sub, x, y;
cout << "Pick your first number you wish to subtract with another one: ";
cin >> x;
cout << "Pick the second number you wish to subtract with the first number: ";
cin >> y;
difference = x - y;
cout << endl << endl;
cout << "The difference of " << x << " and " << y << " is " << difference << endl << endl;
cout << endl << endl;
cout << "Press Y if you want to return to the ";
cout << "main menu, Press N if u want to close the program: ";
cin >> repeatSum;
break;
}
case 3:
{
float quotient, x, y;
cout << "Pick your first number you with to divide with another one: ";
cin >> x;
cout << "Pick the second number you wish to divide with the first one: ";
cin >> y;
if (x == 0 || y == 0)
{
cout << "You can't divide by 0!\n\n";
cout << "That's how the big bang happened!!!\n\n";
cout << "Pick another first number that isn't zero: ";
cin >> x;
cout << "Pick another second number that isn't zero: ";
cin >> y;
difference = x / y;
cout << x << " divided by " << y << " equals " << difference << endl << endl;
cout << "Press Y if you want to return to the ";
cout << "main menu, Press N if u want to close the program: ";
cin >> repeatSum;
break;
}
else
{
quotient = x / y;
cout << x << " divided by " << y << " equals " << difference << endl << endl;
cout << "Press Y if you want to return to the ";
cout << "main menu, Press N if u want to close the program: ";
cin >> repeatSum;
break;
}
cout << endl << endl;
}
}
} while (repeatSum == 'Y' || repeatSum == 'y');
system("pause");
return 0;
}