473,503 Members | 1,818 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 1489
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
24445
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...
7
2134
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...
8
2155
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...
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...
2
9602
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. ...
5
16674
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,...
16
2068
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
2678
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...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7280
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,...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7460
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5014
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...
0
4672
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...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1512
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 ...
0
380
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...

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.