I'm fairly new to programming and am stuck on making a simple menu with switch statements as I keep getting an "Error C2360 Initialization of 'total' is skipped by 'case' label". I am not sure why this is happening or how to fix it! Any help/criticism is appreciated :D
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int choice;
double a, b;
//MENU
cout << setw(20) << setfill('-') << "" << "MENU" << setw(20) << setfill('-') << "" << endl;
cout << "1. Addition " << endl;
cout << "2. Subtraction " << endl;
cout << "3. Multiplication " << endl;
cout << "4. Division " << endl;
cout << endl;
//USER INPUT
cout << "What would you like do do? ";
cin >> choice;
cout << endl;
//SWITCH CASE
switch (choice)
{
case 1:
cout << "Enter 2 numbers: ";
cin >> a >> b;
long double total = (a + b);
cout << "The total is: " << total;
cout << endl;
break;
case 2:
cout << "Enter 2 numbers: ";
cin >> a >> b;
long double totalM = (a * b);
cout << "The total is: " << totalM;
cout << endl;
break;
}
return 0;
}