Why, after selecting the amount of the contribution, would suggest a new amount of contribution instead of a menu display?
-
In selecting 1 paragraph, the user is requested to show the current value of the contribution. When selecting two, insert a new amount of contributions accordingly. If you choose 3, you're leaving the program.
The code I used:
//Program writed with error when choose 1 after it progrum should output menu instead entering new sum of conribution #include <iostream> #include <string>
using namespace std;
int main() {
int contribution;
char choose;cout << "Hello I don't know what I'm doing but still" << endl; cout << "Enter sum of contribution in bank:"; cin >> contribution; cout << endl; while (true) { system("cls"); cout << "What you what to do" << endl; cout << "1.Show sum of contribution" << endl; cout << "2.Change sum of contribution" << endl; cout << "3.Exit" << endl << endl; cin >> choose; switch (choose) { case '1': cout << "Sum of cintribution:" << contribution << endl; system("pause"); case '2': cout << "Enter new sum of contribution:"; cin >> contribution; cout << "New sum of of contrubution is " << contribution << endl; case '3': cout << "Have a good day!"; break; default: cout << "choose 1 2 or 3"; } }
}
Why, after selecting the amount of the contribution, would suggest a new amount of contribution instead of a menu display?
-
because
case
We need to split throughbreak
Otherwise they'll be carried out one by one.case '1': cout << "Sum of cintribution:" << contribution << endl; system("pause"); break; case '2': cout << "Enter new sum of contribution:"; cin >> contribution; cout << "New sum of of contrubution is " << contribution << endl; break; case '3': cout << "Have a good day!"; break; default:
By the way,
3
There is no exit and at least there is a need to implement:while (true) { // ... bool isExit == false; switch (choose) { case '3': cout << "Have a good day!"; isExit = true; break; default: cout << "choose 1 2 or 3"; } if (isExit == true) break; }