I am new to C++, and using gcc for a compiler. This is my first switch statement I have written, but it will not compile, and I can't figure out why (I have stared at it for a while now). The errors messages say there are syntax errors on line 15, and 35, but I can't find them! Sorry about the obvious question.
Thanks for your help.
here is the code
[code=cpp]
#include <iostream>
using namespace std;
char intro(char ans);
//Requires: The user must input one of the following a char values:
//q,Q,m,M,i,I.
//Promises: Returns the input to main.
int main()
{
char ans= intro(char ans);
do
{
switch (ans)
{
case 'q':
case 'Q':
cout<<"Q"<<endl ;
break;
case 'm':
case 'M':
cout<<"M"<<endl ;
break;
case 'i':
case 'I':
cout<<"I"<<endl ;
break;
default:cout<<" improper data"<<endl;
//intro runs good data.
}
}while (ans!=="q"||ans !=="Q"||ans!==" m"||ans!=="M"|| ans!=="i"||ans! =="I");
}
char intro(char ans)
{
cout<<"What the program does, and select one of the 3 options (m,i,q)"<<endl;
cin>> ans;
return ans;
}
[/code]
Thanks for your help.
here is the code
[code=cpp]
#include <iostream>
using namespace std;
char intro(char ans);
//Requires: The user must input one of the following a char values:
//q,Q,m,M,i,I.
//Promises: Returns the input to main.
int main()
{
char ans= intro(char ans);
do
{
switch (ans)
{
case 'q':
case 'Q':
cout<<"Q"<<endl ;
break;
case 'm':
case 'M':
cout<<"M"<<endl ;
break;
case 'i':
case 'I':
cout<<"I"<<endl ;
break;
default:cout<<" improper data"<<endl;
//intro runs good data.
}
}while (ans!=="q"||ans !=="Q"||ans!==" m"||ans!=="M"|| ans!=="i"||ans! =="I");
}
char intro(char ans)
{
cout<<"What the program does, and select one of the 3 options (m,i,q)"<<endl;
cin>> ans;
return ans;
}
[/code]
Comment