I want to do something the user enters the letter Q

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • midway219
    New Member
    • Oct 2014
    • 1

    I want to do something the user enters the letter Q

    Hello,

    I need help with this code please.

    I want to make this do:
    1. when i press Q it will ...

    Code:
    #include <iostream>
    #include <cctype>
    #include <cstdlib>
    #include <iomanip>
    
    
    using namespace std;
    
    
    int main()
    {
    char choice='Y';
    
    int order = 1;
    
    float num1=0, num2=0, num3=0, num4=0, num5=0, total=0;
    int num_customers;
    int sentinel=0;
    const double Price1= 10.35, Price2= 15.35,Price3= 18.25, Price4= 15.55, Price5= 12.55;
    double Sale1=0, Sale2=0, Sale3=0, Sale4=0, Sale5=0;
    
    
    cout <<"		     ¦¦¦¦¦¦¦¦¦¦¦¦¦¦ Hero list ¦¦¦¦¦¦¦¦¦¦¦¦¦\n\n"
         <<"		     ¦(1) Spider Man	         $10.35\n"  
         <<"		     ¦(2) Iron Man	         $15.35\n"
    	 <<"		     ¦(3) Captain America        $18.25\n"
    	 <<"		     ¦(4) Hulk                   $15.55\n"
    	 <<"		     ¦(5) Thor	                 $12.55\n"
    	 <<"		     ¦(6) Total                            \n";
        
    while (order != sentinel)
    {
    
    
    cout<<"Choose what Marvel hero you would like to order:\n";
    
    cin>>order;
    switch(order)
    			{
    				case 1:
                         
                    cout<<"How many  would you like to order:\n";
                    cin>>num1;
    
                	Sale1 = Price1 * num1;
                    
    				cout<<"You have ordered:\n\n";
    				cout<<left<<setw(15)<<"ITEM"<<right<<setw(10)<<"QUANTITY"<<right<<setw(15)<<"UNIT PRICE"<<right<<setw(20)<<"AMOUNT OF SALE\n";
    				cout<<"Spider Man toy:"<<setw(6)<<left<< num1 <<setw(16)<<right<< Price1 <<setw(20) <<right<< Sale1<<endl;
    				
                    break;
                    
                     
    				case 2: 
                    cout<<"How Iron Man toy would you like to order:\n";
    				cin>>num2;
                   
                    Sale2= Price2 * num2;
                    
                    cout<<"You have ordered:\n\n";
    				cout<<left<<setw(15)<<"ITEM"<<right<<setw(10)<<"QUANTITY"<<right<<setw(15)<<"UNIT PRICE"<<right<<setw(20)<<"AMOUNT OF SALE\n";
                    cout<<"Iron Man toy:"<<setw(6)<<left<< num2 <<setw(16)<<right<< Price2 <<setw(20) <<right<<Sale2<<endl<<endl;
                    
                    break;
                    
                    
                    case 3: 
                    cout<<"How many Captain America toy would you like to order:\n";
                    cin>>num3;
                    
                    Sale3= Price3 * num3;
                    
                    cout<<"You have ordered:\n\n";
    				cout<<left<<setw(15)<<"ITEM"<<right<<setw(10)<<"QUANTITY"<<right<<setw(15)<<"UNIT PRICE"<<right<<setw(20)<<"AMOUNT OF SALE\n";
    				cout<<"Captain America toy:"<<setw(6)<<left<< num3 <<setw(16)<<right<< Price3 <<setw(20) <<right<< Sale3<<endl<<endl;
    				
                    break;
                    
                    
                     
                    case 4: 
                    cout<<"How many Hulk toy would you like to order:\n";
                    cin>>num4;
                    
                    Sale4= Price4 * num4;
                    
                    cout<<"You have ordered:\n\n";
    				cout<<left<<setw(15)<<"ITEM"<<right<<setw(10)<<"QUANTITY"<<right<<setw(15)<<"UNIT PRICE"<<right<<setw(20)<<"AMOUNT OF SALE\n";
                    cout<<"Hulk toy:"<<setw(6)<<left<< num4 <<setw(16)<<right<<Price4 <<setw(20) <<right<< Sale4<<endl<<endl;
                    
                    break;
                    
                    
                    
                    case 5: 
                    cout<<"How many Thor toy would you like to order:\n";
                                    cin>>num5;
                    
                    Sale5= Price5 * num5; 
                    
                    cout<<"You have ordered:\n\n";
    				cout<<left<<setw(15)<<"ITEM"<<right<<setw(10)<<"QUANTITY"<<right<<setw(15)<<"UNIT PRICE"<<right<<setw(20)<<"AMOUNT OF SALE\n";
    				cout<<"Thor toy:"<<setw(6)<<left<< num5 <<setw(16)<<right<<Price5 <<setw(20) <<right<<Sale5<<endl<<endl;
    				
                    break;
                    
                    case 6:
                    
                	total = Sale1 +Sale2 + Sale3 + Sale4 +Sale5;
                	
                    cout<<"your total order is:"<< total << endl << endl;
    			
    				
                    break;
                    default: cout<<"Please use the list as a reference for orders made\n";
                    
                    }
    
    
    
    
    
                  }
    
    system("PAUSE");
    return 0;
    }
    Last edited by Frinavale; Oct 20 '14, 03:52 PM. Reason: Added the partial question posted in the title of the thread into the body of the thread so that the code posted has a context and added code tags.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    When you enter a 1 from a keyboard, you can see the 1 on the screen. This is because you have entered he character 1 rather then the integer 1. That is, '1' versus 1.

    Try case '1': rather than case 1: and see if that helps.

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Likewise, if you want to do something in the case where the user enters the character 'Q', you need to add that into your code.

      Also, the variable that stores the user input will need to be changed to a type that can hold the type of input provided.


      -Frinny
      Last edited by Frinavale; Oct 20 '14, 07:35 PM.

      Comment

      • divideby0
        New Member
        • May 2012
        • 131

        #4
        If you're wanting to allow alpha-numeric input, then you might try using a std::string or char array for order instead. Your sentinel would need modification though.

        A char type would work too, but leaves the little newline gremlin to deal with.

        Comment

        Working...