//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;
}

Recommended Answers

All 2 Replies

>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;

Thank you, what a stupid mistake

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.