Hello there!
I just start to learn the basic of C++ in/output functions.
I wrote a program:
#include<iostream>
using namespace std;
int main()
{
int ptype;
char options;
char finops;
do{
cout<<"Select a printer type: ";
cout<<"\n1. HP printer";
cout<<"\n2. Dell printer";
cout<<"\n3. Brother printer";
cout<<"\nYour choice : ";
cin>>ptype;
cin.ignore();
if (ptype == 1) {
cout<<"\nYou selected HP printer.";
cout<<"\nWhich option you want to use?";
cout<<"\nA. Turn on the printer.";
cout<<"\nB. Destroy the printer.";
cin>>options;
cin.ignore();
if (options == 'A', options == 'a'){
cout<<"\nYou turned it on!";
}
else if (options == 'B', options =='b'){
cout<<"\nToss your printer into the fire now!";
}
else {
cout<<"\nI need a correct answer!";
}
}
else if (ptype == 2) {
cout<<"\nYou selected Dell printer.";
cout<<"\nWhich option you want to use?";
cout<<"\nA. Turn on the printer.";
cout<<"\nB. Destroy the printer.";
cin>>options;
cin.ignore();;
if (options == 'A', options == 'a'){
cout<<"\nYou turned it on!";
}
else if (options == 'B', options =='b'){
cout<<"\nToss your printer into the fire now!";
}
else {
cout<<"\nI need a correct answer!";
}
}
else if (ptype == 3) {
cout<<"\nYou selected Brother printer.";
cout<<"\nWhich option you want to use?";
cout<<"\nA. Turn on the printer.";
cout<<"\nB. Destroy the printer.";
cin>>options;
cin.ignore();
if (options == 'A', options == 'a'){
cout<<"\nYou turned it on!";
}
else if (options == 'B', options =='b'){
cout<<"\nToss your printer into the fire now!";
}
else {
cout<<"\nI need a correct answer!";
}
}
else {
cout<<"\nI need a correct answer!";
}
} while(ptype =0,ptype > 3);
cin.get();
return 0;
}
OK, so now the problem is:
1. I can't input the Capital letter into the 'char options', because it'll directly execute the 'else' function, not if/else if functions. I know C++ is a case-sensitive programming language but how can I fix the problem? I want it can read the capital letter.
2. My do-while loop is totally failed! I can loop all of the numbers over integer 3 but I can't loop the number 0. (I use 'for loop', failed too!)
Anyone gives me some suggestions to fix'em?