0
//project.cpp  //compile error-price undeclared (first use this function)         
#include <iostream>       //don't I have it declared in the float line??
#include <fstream.h>
#include <stdlib.h>
using namespace std;
int main()
//PROBLEM:  Create an input file of recently shipped music CD's. The file  should consist of
// the name of the album, quantity shipped and price. Since we do not know how many CD's 
//have been shipped, keep reading the file until all CD's have been read in.  Keep track of
// both the number of different CDs as well as the total number of CDs shipped.
//Your program should determine the value of each CD shipped (quantity * price).
//Create an array to hold this value and print out all values in the array.  
{
  float CD[5];            
  int num;
  float qty=0, val=0; price=0;
  ifstream incd;
  ofstream outcd;

  incd.open("incd.txt");
  outcd.open("outcd.txt");

  if (incd.fail())
  {
    cout<<"Output file doesn't exist!";
    exit(1);
  }
  while (!incd.eof())
  {
    incd>>CD[num]; //how does it read in qty & price and distinguish them??
    for (num=0; num<5; num++)    
    {
      incd>>CD[num];  
      qty = CD[num] + qty;
      val = qty * price;  
    }    

    outcd<<"The value of this CD is: "<<val<<endl;
    val = 0;
    qty = 0;
    price = 0;
  }              
  num = incd.eof ();    //same as while statement???  

  system("PAUSE");
  incd.close();
  return 0;
}
2
Contributors
2
Replies
3
Views
11 Years
Discussion Span
Last Post by kittie
0

>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[B];[/B] price=0;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.