I have to write a program that does this
Write a complete C++ program to solve the following problem.
PROGRAM DESCRIPTION: An unknown number of integers, but no
more than 25, are to be read from the file exam.dat.
(Yes, this means you have to open that file.) Calculate
and output their sum. Next output, one entry per line, each
number and its percentage of the sum. Line these up in columns.
The first column should be 10 characters wide; the second column
should be 7 characters wide, not including the percent sign.
The percentages should be rounded to the nearest tenth. See
sample output below.
PROGRAM INTERNALS: Since the program is so short, you do not
need to define any functions other than main(). You may
assume the input data is error-free and need not be checked for
correctness. The input data file is to be read only once; you
are NOT allowed to open the input file a second time NOR in some
way rewind the input file.
SAMPLE OUTPUT:
Sum Equals: 200
45 22.5%
5 2.5%
30 15.0%
20 10.0%
100 50.0%
and I just need help with one thing and I think i can figure the rest out . . . when I run my program the second for loop won't work (that's why there's a stupid cout to see if it even works) and I don't understand or have a clue why. I would appreciate any help
#include <iostream>
#include <fstream>
using namespace std;
const int size = 25;
int main ()
{
ifstream inFile;
float numbers[size];
float percent[size];
float sum =0;
int counter;
inFile.open("exam.dat");
for (counter =0; numbers[counter] <=size; ++counter)
{
inFile >> numbers[counter];
cout << numbers[counter] << endl;
sum += numbers[counter];
}
for (counter=0; numbers[counter] <=size; ++counter)
{
inFile >> numbers[counter];
percent[counter] = (numbers[counter] / sum) * 100;
cout << percent[counter] << endl;
cout << "bob"<< endl;
}
cout << sum << endl;
return 0;
}