newbie - saving input data and printing out its total from while loop

Discussion in 'C++' started by gaga, Mar 4, 2007.

  1. gaga

    gaga Guest

    hi all,
    i need to write a program - cash register for dummies, so to speak.
    here's the gist - enter the amount of pies that a person wants to get.
    A person can get either, 1, 2, 3, or 4 pizza pies. At the end of the
    day, the worker enters in -1 (negative 1), as the number of pies, to
    indicate to the program that the program is done taking orders for the
    day. When the program is done taking orders, display the total number
    of pies orders, and the amount of money the pies were in total.

    what i have so far is:
    #include <iostream>
    using namespace std;
    const int LOWER_LIMIT = 1;
    const int UPPER_LIMIT = 4;
    int main()
    {
    int pieAMOUNT;

    cout<<"\t\t Greetings, fellow human!"<<endl<<endl;
    while ((pieAMOUNT >= 0) & (pieAMOUNT != -1 )){
    cout<< "Please enter amount between one and four that you wish
    to purchase: ";
    cin>>pieAMOUNT;

    if ((pieAMOUNT >= LOWER_LIMIT) & (pieAMOUNT <= UPPER_LIMIT)) {
    cout<<"Total price for "<<pieAMOUNT<<" pizza pies is
    $"<<pieAMOUNT*5<<endl;
    } else {
    cout<<"You have entered a wrong amount!"<<endl;
    }
    }
    if (pieAMOUNT = -1) {
    cout<<"We are done taking orders for the day"<<endl;
    }
    return 0;
    }

    ----------------------
    i dont understand what features to use in order to save and store and
    later find out the total of the pies/prices entered.
    if you could give me some hints, i would be more than greatful!!

    ps. yes it is a hw, but i dont need the code, i just need to know
    which things to read more about and do it myself.

    thanks :)
    gaga, Mar 4, 2007
    #1
    1. Advertising

  2. gaga

    Mike Wahler Guest

    "gaga" <> wrote in message
    news:...
    > hi all,
    > i need to write a program - cash register for dummies, so to speak.
    > here's the gist - enter the amount of pies that a person wants to get.
    > A person can get either, 1, 2, 3, or 4 pizza pies. At the end of the
    > day, the worker enters in -1 (negative 1), as the number of pies, to
    > indicate to the program that the program is done taking orders for the
    > day. When the program is done taking orders, display the total number
    > of pies orders, and the amount of money the pies were in total.
    >
    >
    > ----------------------
    > i dont understand what features to use in order to save and store and
    > later find out the total of the pies/prices entered.


    Look at the standard library container types, such as std::vector.

    You can write loops (e.g. 'for' or 'while') to for storing, retrieving,
    and accumulating.

    -Mike
    Mike Wahler, Mar 4, 2007
    #2
    1. Advertising

  3. gaga

    Marcus Kwok Guest

    gaga <> wrote:
    > hi all,
    > i need to write a program - cash register for dummies, so to speak.
    > here's the gist - enter the amount of pies that a person wants to get.
    > A person can get either, 1, 2, 3, or 4 pizza pies. At the end of the
    > day, the worker enters in -1 (negative 1), as the number of pies, to
    > indicate to the program that the program is done taking orders for the
    > day. When the program is done taking orders, display the total number
    > of pies orders, and the amount of money the pies were in total.


    Mike Wahler gave you a suggestion to look at the standard containers,
    but see my (unrelated) comment below.

    > what i have so far is:
    > #include <iostream>
    > using namespace std;
    > const int LOWER_LIMIT = 1;
    > const int UPPER_LIMIT = 4;
    > int main()
    > {
    > int pieAMOUNT;
    >
    > cout<<"\t\t Greetings, fellow human!"<<endl<<endl;
    > while ((pieAMOUNT >= 0) & (pieAMOUNT != -1 )){


    At this point, pieAMOUNT is uninitialized and so has an indeterminate
    value. Therefore, your comparison in the while loop condition is
    unreliable.

    --
    Marcus Kwok
    Replace 'invalid' with 'net' to reply
    Marcus Kwok, Mar 5, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steven

    while loop in a while loop

    Steven, Mar 24, 2005, in forum: Java
    Replies:
    5
    Views:
    2,225
    Tim Slattery
    Mar 30, 2005
  2. Uday Bidkar
    Replies:
    4
    Views:
    485
    =?ISO-8859-15?Q?Juli=E1n?= Albo
    Dec 12, 2006
  3. gaga
    Replies:
    2
    Views:
    320
    John Harrison
    Mar 4, 2007
  4. thunk
    Replies:
    1
    Views:
    304
    thunk
    Mar 30, 2010
  5. Isaac Won
    Replies:
    9
    Views:
    366
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page