C++ Homework Help (while loop)?
#include <iostream.h>
#include <conio.h>
int number = 0;
int number2 = 0;
int response = 0;
while (response = 5)
{
void main ()
{
cout<<"Enter the first number: ";
cin>>number;
cout<<"Enter the second number: ";
cin>>number2;
cout<<"Menu Items\n 1)add\n 2)subutract\n 3)multiply\n 4)divide\n";
cin>>response;
if (response != 1-4)
{
cout<<"That is not a valid number"<<endl;
}
switch (response)
{
case 1:
cout<<number + number2<<endl;
break;
case 2:
cout<<number - number2<<endl;
break;
case 3:
cout<<number * number2<<endl;
break;
case 4:
cout<<number / number2<<endl;
break;
case 5:
cout<<response<<endl;
}
}
}
Basically I don't want the program to exit once I get an anser.
So I put in a while loop to equal 5 so every equation gets worked once, but I know it's not right and my reference book doesn't give much insight to what I'm supposed to do. Could someone help me by telling me where to put this while loop in?
It's C++ and I'm using the Micorosoft Visual, this is a ms-dos .exe so at the end of the program I get that "Press any key" thing.
Re: C++ Homework Help (while loop)?
Quote:
Originally posted by freeOn
cin>>response;
if (response != 1-4)
{
cout<<"That is not a valid number"<<endl;
}
Doesn't that equate to "If the response does not equal -3" ? I'll post something later once I test it out, I've been away from any C++ for a long time.
Your "while" is outside of main, by the way... I'm not even gonna guess if that works or not.