c2360 error in unfinished calculator

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <iostream>

using namespace 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;
	}
Last edited on
closed account (48T7M4Gy)
https://msdn.microsoft.com/en-us/library/61af7cx3.aspx

You cannot jump past a declaration with an initializer unless the declaration is enclosed in a block.
Last edited on
Topic archived. No new replies allowed.