explain!

No answer .
Last edited on
You're supposed to show the menu again after the user has made a selection other than B or Q.
You can use any type of loop, but do-while probably makes the most sense here.
so I have to repeat the menu only without answers using increment and decrement !

how can I press Q or B ,While the program is in repetition condition ?

so I have to repeat the menu only without answers

Huh?

using increment and decrement !

Huh?

how can I press Q or B ,While the program is in repetition condition ?

Huh?


You might want to rephrase that.

sorry!
ignore the first part

..
in the problem they said the program should repeat the menu unless the user enters B to go back or Q to quit ...
how to do this part ?
I am relatively sure this is about actually entering the character 'B' (or 'Q') in the terminal rather than an actual keypress. In that case just use whatever method you use to get input (like cin for instance) and compare the result to B and Q.
look here
you might find something
http://www.cplusplus.com/doc/tutorial/control/

and if this did not answered your question please try to be a little more specific
Last edited on

is if-statement needed for B and Q ?

you can use if-statement if that fits well in your program

But when I press 'B' the menu is still Repeated !!
how to do it ?

please help me , I have to know it today :'
Last edited on

HERE is my program ..

//a program that use the selection and repetition constructs.
#include<iostream>

using namespace std;
int main()
{

int x1,x2;//two numbers
int x3;//the number system (the base)
int y;//the number of the operation
int sum,difference,product,quotient,remainder; //operators
char B='B';//to enter new numbers
char Q='Q';//to quit the program

cout << "Please Enter the two numbers: " << endl;
cin >>x1>>x2;

cout << "Enter the number system : " << endl;
cin >> x3;


do {cout << "Enter the number of the operation: " << endl;
cin >> y;



if (y==1)
{
sum = x1+x2;
cout << sum << endl;
}
else if (y==2)
{difference = x1-x2;
cout << difference << endl;
}
else
if (y==3)
{product = x1*x2;
cout << product << endl;
}
else

if (y==4)
{ quotient = x1/x2;
cout << quotient << endl;
}

else if(y==5)
{
remainder = x1%x2;
cout << remainder << endl;
}
else if (y==Q)
{cout << "Quit" << endl;}
else if (y==B)
{cout << "Please Enter the two numbers: " << endl;
cin >>x1>>x2;

cout << "Enter the number system : " << endl;
cin >> x3;}
}

while(cout << "1. The sum of the two numbers " << endl
<< "2. The difference of the two numbers " << endl
<< "3. The profuct of the two numbers " << endl
<< "4. The quotient of the two numbers " << endl
<< "5. The remainder when the first number is divided by the second " << endl);


return 0;

}
you realise that you canĀ“t do
if (int == char) in your code?

without changing too much you can put somewhere that if y=6 then Q and if y=7 then B or whatever you want!
Or you can simply declare a char variable and read it...and you just make the test
if (char_var=='B' and same for Q ....

Have fun!
Last edited on
I think that maybe the trap in the exercise: reading integers and characters to the same variable. The simpler way is to think '1','2' in term of characters instead of integers, read them as characters. But I think there's still some other problems in his code.
Topic archived. No new replies allowed.