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

G

gaga

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 :)
 
M

Mike Wahler

gaga said:
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.

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
 
M

Marcus Kwok

gaga said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top