//project.cpp                compiles
//Need to 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.  

#include <iostream>               
#include <fstream.h>
#include <stdlib.h>
using namespace std;
int main()

{
      //if is digit peek
//see isstream.peek
float CD[5];  
char album[22];     
int num;
float totqty =0, 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);
  }
    
  
    for (num=0; num<5; num++)    
    {
      incd.getline(album,22);  
      incd>>qty;                   //reading 5 files, has name only of 1st album, all values 0
      incd>>price;
      val = qty * price; 
      // cout<<val<<endl;         //when test with this, prints 5 zeroes
      outcd<<"The value of "<<album<<"CD is: "<<val<<endl;  //putting blank spaces in + putting 0
      }                    //how will do cout for each album if not in loop
      totqty = totqty + qty;            //total CDs shipped
      //cout<<totqty<<endl;              //when test with this, prints 0
   
    val = 0;
    qty = 0;
    price = 0;
             
  outcd<<"The total CDs shipped is: "<<totqty<<endl; //should be 54
   
system("PAUSE");
incd.close();
	return 0;
}

<< moderator edit: added [code][/code] tags >>

:?:

What's it doing/not doing?

Posting code is one thing, but if you describe what is supposed to happen, someone can help you target what the problem is.

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.