944,085 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1574
  • C++ RSS
May 6th, 2005
0

PLEASE help with project - compile error

Expand Post »
C++ Syntax (Toggle Plain Text)
  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. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kittie is offline Offline
17 posts
since Apr 2005
May 6th, 2005
0

Re: PLEASE help with project - compile error

>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;
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
May 8th, 2005
0

Re: PLEASE help with project - compile error

Thank you, what a stupid mistake
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kittie is offline Offline
17 posts
since Apr 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Help. This is a strange problem
Next Thread in C++ Forum Timeline: Winsock Send File To Client Help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC