Problem: Write a pgoramthat uses a structure to store the following information:
Name, IdNum, Test1Score through Test4Score, average, and grade.
function to ask the user for student's name, etc.
The average score should be calculated and stored in the Average member of the structure should be calculated in their own functions.
Course grade should be computed based on the following scale:
91-100 = A
81-90 = B
etc.
I am trying to figure out how to call the information into a function that has the user's input for Test1Score through Test4Score so I can figure out the average.
Can someone assist me? I do not know how to pass data into a function from another function. "I am a newbie!"
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
struct school
{
string name;
int IdNum;
int Test1Score,
Test2Score,
Test3Score,
Test4Score,
Grade;
double average;
};
int getInfo(school&);
int getAvg(student, int total);
int main()
{
school student;
getInfo(student);
getAvg(student, total);
return 0;
}
int getInfo(school &student)
{
int total = 0;
cout << "Enter Student's Name: ";
cin >> student.name;
cout << "Enter Student's ID: ";
cin >> student.IdNum;
cin.ignore();
cout << "Enter Student's score for Test# 1 ";
cin >> student.Test1Score;
while(student.Test1Score < 0 || student.Test1Score > 100)
{
cout << "Enter grade between 0 & 100: ";
cin >> student.Test1Score;
}
cout << "Enter Student's score for Test# 2 ";
cin >> student.Test2Score;
while(student.Test2Score < 0 || student.Test2Score > 100)
{
cout << "Enter grade between 0 & 100: ";
cin >> student.Test2Score;
}
cout << "Enter Student's score for Test# 3 ";
cin >> student.Test3Score;
while(student.Test3Score < 0 || student.Test3Score > 100)
{
cout << "Enter grade between 0 & 100: ";
cin >> student.Test3Score;
}
cout << "Enter Student's score for Test# 4 ";
cin >> student.Test4Score;
while(student.Test4Score < 0 || student.Test4Score > 100)
{
cout << "Enter grade between 0 & 100: ";
cin >> student.Test4Score;
}
total += student.Test1Score + student.Test2Score + student.Test3Score +
student.Test4Score;
return total;
}