Hi there! I Apologize for any inconvenience, however I have a question of which I have been unable to solve. In the code below, I would like to include a case within the switch command, in which when a character is entered, instead of an integer, an error message, along the lines of "Did not understand, please re-enter" is displayed. Unfortunately I have not been able to achieve this. I believed that if I were to put:
1 2 3
case (char)bill1
cout << "Did not understand, please re-enter";
continue;
The problem would be fixed. Unfortunatley 'Continue' statements are not accepted in a Switch statement, and casting bill1 as a char would not work either. Any ideas?
cout << "\n\nWelcome to the Bill Payer Application! \n\n" << "Please enter the grand sum of money that can be allocated to paying your bills this cycle. \n\n" << "Grandsum: $";
cin >> grandsum;
cout << "\n\nYou have " << grandsum << " dollars to allocate towards bills this cycle.\n\nPlease enter your first bill price and press enter. \n\n[!]Type 0 and press enter in any of the fields to immediatley exit.[!]\n\n";
cout << "Bill 1 price: $";
cin >> bill1;
billgrand = bill1;
int bill1;
switch (bill1)
{
case 0:
goto billgrand;
break;
default:
int bill2;
cout << "Bill 2 price: $";
cin >> bill2;
billgrand = bill1+bill2;
switch (bill2)
{
case 0:
goto billgrand;
break;
default:
int bill3;
cout << "Bill 3 price: $";
cin >> bill3;
billgrand = bill1+bill2+bill3;
switch (bill3)
{
case 0:
goto billgrand;
break;
default:
int bill4;
cout << "Bill 4 price: $";
cin >> bill4;
billgrand = bill1+bill2+bill3+bill4;
switch (bill4)
{
case 0:
goto billgrand;
break;
default:
int bill5;
cout << "Bill 5 price: $";
cin >> bill5;
billgrand = bill1+bill2+bill3+bill4+bill5;
switch (bill5)
{
case 0:
goto billgrand;
break;
default:
int bill6;
cout << "Bill 6 price: $";
cin >> bill6;
billgrand = bill1+bill2+bill1+bill4+bill5+bill6;
switch (bill6)
{
case 0:
goto billgrand;
break;
default:
int bill7;
cout << "Bill 7 price: $";
cin >> bill7;
billgrand = bill1+bill2+bill1+bill4+bill5+bill6+bill7;
switch (bill7)
{
case 0:
goto billgrand;
break;
default:
int bill8;
cout << "Bill 8 price: $";
cin >> bill8;
billgrand = bill1+bill2+bill1+bill4+bill5+bill6+bill7+bill8;
switch (bill8)
{
case 0:
goto billgrand;
break;
default:
int bill9;
cout << "Bill 9 price: $";
cin >> bill9;
billgrand = bill1+bill2+bill1+bill4+bill5+bill6+bill7+bill8+bill9;
switch (bill9)
{
case 0:
goto billgrand;
break;
default:
int bill10;
cout << "Bill 10 price: $";
cin >> bill10;
billgrand = bill1+bill2+bill1+bill4+bill5+bill6+bill7+bill8+bill9+bill10;
}
}
}
}
}
}
}
}
}
I understand the code is most likely unnecessarily bulky and incredibly inefficient, however I am only 14 and very new to the language of C++. If you have any questions or need clarification please do not refrain from asking. Again, thank you.
Thank You CodeGoggles! However, I understand that, but if I'm using 0 as an exit number, and all other numbers are to be accepted by the default case, how am I to make a case that would return an error message if a character, instead of an integer, is to be entered?
I am sure you can do what you want but the current structure of your switch is not how switch's are meant to be used. each case is supposed to have its own value. Your cases are also inside the previous case. And that will invalidate the switch altogether.
I want to help you so if you could post your entire code particularity what's happening with billgrand. I would be ablel to edit it and comment the areas I changed for your clarification.