473,569 Members | 2,735 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

can cin.get() be reset so it is no longer EOF?

2 New Member
I was supposed to write a program that takes inputs of what products were sold for day number 1 ... 7 then total the retail price of those products for the week. When run this program reads the first time through on day one, but then it just prints out everything without waiting for input the second ... seventh time around. And it prints the total... well totaly wrong.

Any help would be greatly appreciated.

Here is my code:
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main(){
  5.     int product;
  6.     int one[7];
  7.     int two[7];
  8.     int three[7];
  9.     int four[7];
  10.     int five[7];
  11.     double total = 0;
  12.     for(int i = 0; i < 7; i++){
  13.         cout << "What products were sold on day " << i+1 << " (1 - 5 or EOF to end entry)? ";
  14.         while( (product = cin.get()) != EOF){
  15.             switch(product){
  16.                 case '1':
  17.                     ++one[i];
  18.                     break;
  19.  
  20.                 case '2':
  21.                     ++two[i];
  22.                     break;
  23.  
  24.                 case '3':
  25.                     ++three[i];
  26.                     break;
  27.  
  28.                 case '4':
  29.                     ++four[i];
  30.                     break;
  31.  
  32.                 case '5':
  33.                     ++five[i];
  34.                     break;
  35.  
  36.                 case ' ':
  37.                 case '\n':
  38.                 case '\t':
  39.                     break;
  40.  
  41.                 default:
  42.                     cout<< "Incorrect entry. \n";
  43.             }
  44.         }
  45.     total += (one[i]*2.98 + two[i]*4.5 + three[i]*9.98 + four[i]*4.49 + five[i]*6.87);
  46.     }
  47.     cout << "Total retail price for the week is " << total;
  48.     cin.get(); 
  49.     return 0;
  50. }
  51.  
ps while((product cin.get ()) != EOF) and a switch statement were both supposed to be used also as part of the assignment.
Oct 12 '07 #1
3 1494
weaknessforcats
9,208 Recognized Expert Moderator Expert
Please use code tags. I added them for you this time.
Oct 12 '07 #2
quiznos
2 New Member
i dont know how to post code tags but thanks. can anyone help me with this?
Oct 15 '07 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
When you post look to the right at the Reply Guidelines message box.

It's the third bullet.
Oct 15 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

10
24462
by: Andreas | last post by:
Hi! Is it possible to get a time event at a specific time, for instance eight a'clock? My program is running in the background and is minimized to the tray bar. If not, is there a smooth way to accomplish this in a different way? Best regards, Andreas Lundgren
7
2138
by: Christoph Pieper | last post by:
Hi, we've the following problem : We have an asp-application which sets the cookie on first login. The cookie will never be touched during user access. The user can work the whole day, but after 6 to 7 hours, the cookie get 2-4 new asp-sessionid's thus overwriting the very first entries in the cookie. Does anyone had the same problem or...
8
2167
by: spike | last post by:
My prygram goes through a string to find names between '\'-characters The problem is, parts of the name in sTemp remains if the new name is shorter than the old name. code --------------------------------------------------- char sTemp; char sText = "THELONGESTNAME\\samantha\\gregor\\spike\\..."; // and so on...
4
5415
by: whoopdaddy | last post by:
We are streaming a PDF file out of an ASPX page in IIS 5 using Response.WriteFile so the user does not need permissions to the directory where the files are stored. This works great when the user is on a fairly fast network connection or when the PDF is not too large. However, for users on slow connections that try to download a large PDF...
2
9609
by: am72de | last post by:
Hi all, I have a problem with the DataTable.Reset(). After resetting the DataTable the count of the DataView is no longer equal with the DataTable.Rows.Count, so the second Assert fails. See the simplified example below... Does anybody has this behaviour too?
5
16683
by: trint | last post by:
Hi, I have several arrays that look like this: string productsString0 = new string; After they are no longer needed, How can I reset them as though the program were just started? Thanks, Trint
16
2074
by: Giovanni D'Ascola | last post by:
Hi. I noticed that <input type="reset"actually don't enable checkbutton which are checked by default after they have been disabled by javascript. It's a bug?
2
2693
by: ilany | last post by:
Hi to all.. The relationships in my database depend on autonumbered primary keys. Occasionally access will crash, causing all primary key values to be reset in tables. Now that the primary keys are rest, the table relationships are no longer valid. Example: For two tables, Suppliers, and Addresses In Addresses the promary key is...
0
7921
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6278
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2107
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1208
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.