PLEASE help with project - compile error

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2005
Posts: 17
Reputation: kittie is an unknown quantity at this point 
Solved Threads: 0
kittie kittie is offline Offline
Newbie Poster

PLEASE help with project - compile error

 
0
  #1
May 6th, 2005
  1. //project.cpp //compile error-price undeclared (first use this function)
  2. #include <iostream> //don't I have it declared in the float line??
  3. #include <fstream.h>
  4. #include <stdlib.h>
  5. using namespace std;
  6. int main()
  7. //PROBLEM: Create an input file of recently shipped music CD's. The file should consist of
  8. // the name of the album, quantity shipped and price. Since we do not know how many CD's
  9. //have been shipped, keep reading the file until all CD's have been read in. Keep track of
  10. // both the number of different CDs as well as the total number of CDs shipped.
  11. //Your program should determine the value of each CD shipped (quantity * price).
  12. //Create an array to hold this value and print out all values in the array.
  13. {
  14. float CD[5];
  15. int num;
  16. float qty=0, val=0; price=0;
  17. ifstream incd;
  18. ofstream outcd;
  19.  
  20. incd.open("incd.txt");
  21. outcd.open("outcd.txt");
  22.  
  23. if (incd.fail())
  24. {
  25. cout<<"Output file doesn't exist!";
  26. exit(1);
  27. }
  28. while (!incd.eof())
  29. {
  30. incd>>CD[num]; //how does it read in qty & price and distinguish them??
  31. for (num=0; num<5; num++)
  32. {
  33. incd>>CD[num];
  34. qty = CD[num] + qty;
  35. val = qty * price;
  36. }
  37.  
  38. outcd<<"The value of this CD is: "<<val<<endl;
  39. val = 0;
  40. qty = 0;
  41. price = 0;
  42. }
  43. num = incd.eof (); //same as while statement???
  44.  
  45. system("PAUSE");
  46. incd.close();
  47. return 0;
  48. }
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,855
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 755
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: PLEASE help with project - compile error

 
0
  #2
May 6th, 2005
>don't I have it declared in the float line??
No. If you had preceded it with a comma instead of a semicolon then yes:
float qty=0, val=0; price=0;
New members chased away this month: 4
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 17
Reputation: kittie is an unknown quantity at this point 
Solved Threads: 0
kittie kittie is offline Offline
Newbie Poster

Re: PLEASE help with project - compile error

 
0
  #3
May 8th, 2005
Thank you, what a stupid mistake
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1476 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC