i have been asked to make a gradebook where i ask the user to enter a students first and last name major as well as three assignment scores and their average. I have to do this for three students and then find the lowest/highest grade per assignment and then the mean score for each assignment.
My problem is that when i try to save the information to a file its only saving the data from the first set in the loop, not the other two. Any help would be greatly appreciated.
#include<iostream>
#include<fstream>
#include<string>
std::ifstream inputHandler;
std::ofstream outputHandler;
usingnamespace std;
int main()
{
int rank;
int assignmentScore1;
int assignmentScore2;
int assignmentScore3;
int averageScore;
int count = 0;
string firstName;
string lastName;
string major;
for (count = 0; count <= 2; count++)
{
// Get student's first name
std::cout << "Enter the student's first name. ";
std::cin >> firstName;
// Get student's last name
std::cout << "Enter the student's last name. ";
std::cin >> lastName;
// Get student's major
std::cout << "Enter the student's major. ";
std::cin >> major;
// Get 1st assignment score
std::cout << "Enter the student's score for assignment 1. ";
std::cin >> assignmentScore1;
// Get assignment score 2
std::cout << "Enter the student's score for assignment 2. ";
std::cin >> assignmentScore2;
// Get assignment score 3
std::cout << "Enter the student's score for assignment 3. ";
std::cin >> assignmentScore3;
//Get average assignment score
averageScore = (assignmentScore1 + assignmentScore2 + assignmentScore3) / 3;
std::cout << "Average score is:" << averageScore << endl;
outputHandler.open("StudentData.txt");
outputHandler << firstName << lastName << major << assignmentScore1 << assignmentScore2 << assignmentScore3 << std::endl;
}
after I did this i was going to read from the lines in the txt file to determine the lowest/highest and average score. Would that be an appropriate thing to do?
p.s. if i put the output handler code on the outside of the bracket it gives me the last one of the loop
#include<iostream>
#include<fstream>
#include<string>
std::ifstream inputHandler;
std::ofstream outputHandler;
usingnamespace std;
int main()
{
int assignmentScore1;
int assignmentScore2;
int assignmentScore3;
int averageScore;
int count = 0;
string firstName;
string lastName;
string major;
string rank;
for (count = 0; count <= 2; count++)
{
// Get student's first name
std::cout << "Enter the student's first name. ";
std::cin >> firstName;
// Get student's last name
std::cout << "Enter the student's last name. ";
std::cin >> lastName;
// Get student's major
std::cout << "Enter the student's major. ";
std::cin >> major;
// Get student's rank
std::cout << "Enter the student's rank. ";
std::cin >> rank;
// Get 1st assignment score
std::cout << "Enter the student's score for assignment 1. ";
std::cin >> assignmentScore1;
// Get assignment score 2
std::cout << "Enter the student's score for assignment 2. ";
std::cin >> assignmentScore2;
// Get assignment score 3
std::cout << "Enter the student's score for assignment 3. ";
std::cin >> assignmentScore3;
//Get average assignment score
averageScore = (assignmentScore1 + assignmentScore2 + assignmentScore3) / 3;
std::cout << "Average score is:" << averageScore << endl;
}
outputHandler.open("StudentData.txt");
outputHandler << firstName << lastName << major << rank << assignmentScore1 << assignmentScore2 << assignmentScore3 << std::endl;
I have also tried simply putting: outputHandler << firstName << lastName << major << rank << assignmentScore1 << assignmentScore2 << assignmentScore3 << std::endl;
inside the bracket and leaving :outputHandler.open("StudentData.txt"); outside and that did not work as well.
Ah thank you! It works now! However when I try to read the data from the txt file to average all the scores from assgnment 1, it will only read the data from the last set.. Not sure if its a similar solution as my first problem.
I am trying to find the minimum/maximum score from each assignment as well as the average score for each assignment.
ex. Student 1 assignment 1 score = 95 - Student 2 assignment 1 score = 78 - Student 3 assignment 1 score = 84 find the lowest grade from assignment 1, and the same for max and average and do it for each of the three assignments
I dont know how to input say the assignment 1 score from each of the three students. I have been playing around with trying to draw the info out based on the students name but its not working. This is my first code I have written so im not sure if this is something complicated or very simple. Maybe I have to do something inside the loop that sets say the first entered assignment score 1 to a variable say assignment1a, then the next person is asignment1b but again im not quite sure if that is possible or the best way. Thanks for the help!
I have to make a grade book program where the user enters 3 assignments for 3 students as well as their name class and major then find the average for each student then the average score of the class for each assignment then the lowest and highest score for each assignment and then save it to a txt file. I've never coded before and assumed I should have the user enter all the info for the students and their scores find the average . Save it to a file then draw the information out to find the highest lowest and average . Is there a way to find all of the info first then save it to a txt file???
We have covered them but my knowledge on them is pretty minimum, I only did it the way I did because thats all I know how to do. Do you think it would be worth it to start over? I know that code i wrote is pretty simple but it took me quite a bit of time to do...
We have covered them but my knowledge on them is pretty minimum, I only did it the way I did because thats all I know how to do.
The purpose of homework is to reinforce topics you've covered in class. Since you've stated you've studied vectors and structures, then I suggest you rethink your code and and use both of these features to solve this problem.
Okay guys, I re wrote the code using arrays and I have gotten pretty far, my only problem now is when im trying to find the min/max/average of the three assignments my program is only giving me the min/max/average for the last assignment, I have been playing around with it for some time and i can't seem to figure out whats wrong.