# Declaring Integrars in a Switch // Case situtation

• 10-01-2001
D4050
Declaring Integrars in a Switch // Case situtation
Hey guys...Im trying to declare z to either times multiply add subtract or devide. I take 2 numbers from the user at the beggining right...and then i ask them weather they wanna subtract (S) multiply (M) devide (D) or add (A) and watever they type in...the 2 numbers will do..heres the switch code:

switch(entry)
{
case 'm':
case 'M':
int z = x*y;
break;

case 'D':
case 'd':

break;

case 'S':
case 's':

break;

case 'A':
case 'a':

break;

default:
{
cout<<"Sorry, You've entered an invalid character. Please retry!"<<endl;
}

}

where it sais <<z is where its gonna do watever method to the 2 numbers x and y. Where do i declare z each new time? how do i declare it?
• 10-01-2001
Salem
When you did
cin >> x;
cin >> y;

Did you do a
cin >> entry;

And how did you declare entry.

Otherwise, it looks good.
• 10-01-2001
D4050
Yea i did..cuz the entry is for weather the user types in S M D or A....and the X and Y is for the numbers..and the Z is for the 2 numbers either S (subtracted) M (multiplied) D (devided) or A (added) ...but i wanna know where i declare that z = x*y for multipling or z = x-y for subtracting.etc...in the cases..where would i declare that?
• 10-01-2001
Salem
OIC
Declare z when you declare x and y

int x, y, z;
• 10-01-2001
D4050
Yes yes yes!!!!!!! Its all coming together now!! I understand!!!! :)
Im gonna take it a stetp further now...im now doing:

cout<<" "<<x " multiplied by "<<y ", equals "<<z <<endl;

wat is wrong with that? theres an error...but i dont know how to correct it
• 10-01-2001
D4050
nvm got it. heh...thanks guys:)....next question...how would i do a loop kinda thing..where at the end..the user can press a key or sumthin and it reduz the program all over again without reopening it? anyone help?
• 10-01-2001
Govtcheez
use a while loop...

char GoOn = y;
while(GoOn == y)
{
//do stuff
//ask if user wants to go on
}
• 10-01-2001
D4050
sorry im not familiar with while declaration....can u explain the code for me plz?
• 10-01-2001
kermi3
http://www.cprogramming.com/tutorial/lesson3.html

That's all about loops...if you still have question lemme know and I'll edplan in more detail.
• 10-01-2001
D4050
yea im totally pysched out. could you go through the code with me blocks at a time? id really appreciate it