How to apply while loops when I want to repeat something?
problem:
Write a C++ calculator that takes two numbers and a letter indicating an
operation to be performed. The user enters the letter and the program performs the operation depending on the letter as the following menu:
A: Add (the two numbers)
S: Subtract
M: Multiply
D: Divide
The program should repeat the menu unless the user enters ‘B’ (for “Back”) in which case the program will (again) prompt the user for two numbers and a number system. The program should not exit unless the user presses the character ‘Q’ (for “Quit”).
I solved it but I don't know how to apply loops! :/ help me my program:
#include<iostream>
using namespace std;
int main()
{
int x1,x2;
char x;
char a= 'a';
char s = 's';
char m = 'm';
char d = 'd';
char q='q';
int add,subt,multip,divide;
cout << "Enter the two numbers: " << endl;
cin >> x1 >> x2;
I solved it but I don't know how to apply loops! :/ help me
Take a look at the link I posted, just scroll down to the section titled Iteration structures (loops) it shows you examples on how to use a while loop.
If you're confused about how it works after that, post back on what you're having problems understanding.
Hint : your while condition would need to compare the user input to 'Q'