Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > newbie - saving input data and printing out its total from while loop

Reply
Thread Tools

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

 
 
gaga
Guest
Posts: n/a
 
      03-04-2007
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

 
Reply With Quote
 
 
 
 
Mike Wahler
Guest
Posts: n/a
 
      03-04-2007

"gaga" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ps.com...
> 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


 
Reply With Quote
 
 
 
 
Marcus Kwok
Guest
Posts: n/a
 
      03-05-2007
gaga <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Triple nested loop python (While loop insde of for loop inside ofwhile loop) Isaac Won Python 9 03-04-2013 10:08 AM
Its a bird, its a plane, no ummm, its a Ruide thunk Ruby 1 03-30-2010 11:10 AM
saving input data and showing its total value in while loop gaga C++ 2 03-04-2007 09:38 AM
Whats the difference between while loop in Windows message loop and while(1) Uday Bidkar C++ 4 12-12-2006 12:30 PM
while loop in a while loop Steven Java 5 03-30-2005 09:19 PM



Advertisments