Thread: Newbie please help me

  1. #1
    Unregistered
    Guest

    Question Newbie please help me

    Hi,

    Please tell me what I am doing wrong.When I press A,B,C it just doesnt enter into switch case.why??
    OUtput on the screen is "incorrct productcode entered.total is 0"

    Actually,I want to find the total sales for entire week so should I put in while loop and keep counter 7 ???

    Thankx in advance.
    #include<iostream>

    using std::cout;
    using std::cin;
    using std::endl;
    int main()
    {
    int ans,qty,counter;
    double prdA,prdB, prdC,saleA,saleB,saleC,total;
    saleA=0,saleB=0,saleC=0,total=0;
    prdA=2.98;
    prdB=4.50;
    prdC = 9.98;
    counter=0;

    cout<<"enter the product A-C "<<endl;
    cin>>ans;


    switch(ans)
    {
    case 'A':
    case 'a':
    {
    cout<<"enter qty"<<endl;
    cin>>qty;
    saleA=prdA*qty;
    cout<<"ur sale is"<<saleA<<endl;
    break;
    }

    case 'B':
    case 'b':
    {
    cout<<"enter qty"<<endl;
    cin>>qty;
    saleB=prdB*qty;
    cout<<"ur sale is"<<saleB<<endl;
    break;
    }
    case 'C':
    case 'c':
    {
    cout<<"enter qty"<<endl;
    cin>>qty;
    saleC=prdC*qty;
    cout<<"ur sale is"<<saleC<<endl;;
    break;
    }

    default:
    {
    cout<<"incorrect productcode entered"<<endl;
    break;
    }
    }


    total = saleA+saleB+saleC;
    cout<<"total is "<<total;
    return 0;
    }

    Please guide me.....

  2. #2
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    You declare ans as an int and then compare it to things like 'A' and 'B'... Let's ponder this.

  3. #3
    Unregistered
    Guest

    Lightbulb Thankx But...

    Hi,
    thanks for pointing me out for such a silly mistake.I converted it into char.
    but my second query is now i want to find total sales for a entire week,so how to put it in while loop ?
    thanks once again.

  4. #4
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    Smth like this:

    int count = 0;

    while(count <7)
    {
    do stuff
    count++;
    }

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Actually, if you're dealing with chars, I doubt you can do it with a loop without a lot conversion to int and enums. You should just go through a bunch of times with the += operator.

  6. #6
    Unregistered
    Guest
    Thank you all for replying my post.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getting to grips with allegro and ms vc++ (newbie)
    By jimjamjahaa in forum C++ Programming
    Replies: 4
    Last Post: 11-18-2005, 07:49 PM
  2. Newbie in problem with looping
    By nrain in forum C Programming
    Replies: 6
    Last Post: 11-05-2005, 12:53 PM
  3. Newbie Programmer
    By Extropian in forum C++ Programming
    Replies: 3
    Last Post: 05-18-2004, 01:17 PM
  4. Some help for a newbie?
    By Ilmater in forum C++ Programming
    Replies: 23
    Last Post: 04-19-2004, 07:44 PM
  5. Newbie Game Develpoers Unite!
    By Telenosis in forum Game Programming
    Replies: 10
    Last Post: 06-22-2002, 02:02 PM