whats wrong with this switch?
what exactly is wrong with this switch? the program always goes to the default
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
double a;
double b;
int Format;
std::cout<<"What Format Is The Problem In"<<std::endl;
std::cout<<"1 = a^2-b^2"<<std::endl;
std::cout<<"2 = a^2+2ab+b^2"<<std::endl;
std::cout<<"3 = a^2-2ab+b^2"<<std::endl;
std::cout<<":";
std::cin>>Format;
switch (Format){ /*right here*/
case '1':
std::cout<<"Enter a: ";
std::cin>>a;
std::cout<<"Enter b: ";
std::cin>>b;
std::cout<<"("<<a<<"+"<<b<<")("<<a<<"-"<<b<<")"<<std::endl;
std::cin.ignore();
case '2':
std::cout<<"Enter a: ";
std::cin>>a;
std::cout<<"Enter b: ";
std::cin>>b;
std::cout<<"("<<a<<"+"<<b<<")^2"<<std::endl;
std::cin.ignore();
case '3':
std::cout<<"Enter a: ";
std::cin>>a;
std::cout<<"Enter b: ";
std::cin>>b;
std::cout<<"("<<a<<"-"<<b<<")^2"<<std::endl;
std::cin.ignore();
default:
std::cout<<"Invalid Option"<<std::endl;
std::cin.ignore();}
|
and yea I know the formatting is bad I just copied and pasted this part of the code and was too lazy too fix it.
case '1' is looking for the char 1. To get the int 1, use case 1, without the quotes.
either change format to be char (instead of an int), or have your case labels be integers instead of chars (ie: case 1:
not case '1':
)
whoops I didn't think about that, thanks
Topic archived. No new replies allowed.