I am looking for a hint in the right direction regarding my program. I don't just want the answer because I want to be able to understand it. The part in bold is the part I am need of assistance with. I'm using my input file that has a FirstName LastName and program/test scores. However, when trying to run my output my calculations aren't being taken accounted for?
Example from input file:
James Bond 77 87 76 82 92 96 90
#include <iostream>
#include <iomanip>
#include <fstream> //Step One
using namespace std;
int main (){
//START OF MAIN
system("color f0");
//Description Header
//Add Header
cout<<"Blah Blah Welcome \n"<<endl;
cout<<"Examine the input text file (input.txt) before you continue\n"<<endl;
ifstream fin; //Step Two
ofstream fout; //Step Two
//Start of Step Three
fin.open("input.txt");
fout.open("output.txt");
//End of Step Three
First of all, I think that you need to use #include<string> for this program.
And you are going to have to read in the data from the file before you can do any calculations on it. Basically, it looks like you did your "fin" too late. Read in all the data first and then you can do endless calculations on it. So start with something like this (I'm assuming that you haven't learned how to use arrays yet so I'll do it with several variables)
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
string fName, lName; // store first name and last name in these
int scoreOne, scoreTwo, scoreThree, scoreFour, scoreFive, scoreSix, scoreSeven; // store the 7 scores in these
ifstream fin;
fin.open("input.txt");
fin >> fName >> lName >> scoreOne >> scoreTwo >> scoreThree >> scoreFour >> scoreFive >> scoreSix >> scoreSeven;
Then you will have all the data and you can manipulate it using the variables in any way that you like. Hope this helps.
That worked great! Except for some reason the calculation is off? Sorry for all the questions haha I tried to do my fair share of research. And thanks for the tip on setting up my int variables more efficiently
It looks to me like the program should be returning 82 since you are using an int data type for the average. The reason you are not getting the 85 you are looking for is because you told the program to just use the first 5 scores and divide them by 5. When you did the math yourself, you used all 7 scores.