**NEED help with program!!!!!!!!

My school forced me to take this class because I'm getting an Associate in science (im going for physical therapy) and they said i need at least one computer class. Basically, I am writing a program that needs to read

"This program will read each line of invoice1.txt and print a
statement indicating the item and its cost. When the file
is exhausted, it will print the sum of all of the costs.


hammer 9.95
saw 20.15
shovel 35.40

Total 3 items $ 65.50"

Most of my program is written because my teacher wrote it, my program is reading everything to the cost of the shovel, but i need help for it to read "total 3 items $ 65.50". basicall add them all



Here your reading program:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <conio.h>
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    ifstream myfile;
    string count[100];
    int line=0;
    float prize_count[100],total_prize;
    myfile.open("c:/invoice1.txt");
    prize_count[0]=0;
    while(!myfile.eof())
    {
                      myfile>>count[line]>>prize_count[line];
                      
                      cout<<count[line]<<" "<<prize_count[line]<<endl;
                      if(line>0){
                      prize_count[line]=prize_count[line]+prize_count[line-1];}
                      line++;
                      
                      
    }
    total_prize  = prize_count[line-1];
    cout<<endl<<"Total "<<line<<" items $ "<<total_prize;
    myfile.close();
    getch();
    return 0;
}
Last edited on
Topic archived. No new replies allowed.