0

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?

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Ancient Dragon
0

line 25 is constructed incorrectly. Should be: if( (options == 'A' ) || (options == 'a') Notice it used || or operator, not a comma operator. Same problem with line 72. Do not use the comma operator when the || or operator is intended.

Edited by Ancient Dragon: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.