I'm still not getting what you're driving at. I understood the tutorial on arrays, but what I'm asking for wouldn't it be in the form of say
1 2 3 4 5 6
|
string student_name[3];
x = student_name[0];
cin>>x;
cout<<x;
|
etc. etc. like I want to be able to output each of the elements in the array of say student_name, grade_1, grade_2 and even add_ent, but it won't allow me to do that, I would have to attach a variable (or a value) in this case to the array element so I can output it. But, the thing is you're asking for the user's input of the array, so the user's 3 inputs for the certain element should be entered in the program. That's the only way I see it happening where I can output all three at once. The code you wrote literally has the same output as my previous one, it still loops it till the third time it has prompt the user. How do I get it to prompt the user three times, but the last time and
the last time only it outputs all three of the inputs for each entry?
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
#include<iostream>//including input output functions of library
using namespace std;//avoid naming conflicts
struct Gradebook //struct;
{//start of struct
string student_name;// initialising variables
int grade_1, grade_2;
double grade_avg;
string add_ent;
void gradeclc()//gradeclc function
{//start of gradeclc
grade_avg = (grade_1 + grade_2)/2; //grade average calculations
if (grade_avg>=60)//if statement
{
add_ent = "Pass"; // assigning a string to the add_ent
}
else if (grade_avg < 60)
{
add_ent = "Fail";
}
}//end of gradeclc function
void printmsg()//printmsg function
{//start of printmsg
gradeclc();//calling gradeclc function
//output headings
cout<<student_name<<"\t\t\t"<<grade_1<<"\t\t"<<grade_2<<"\t\t"<<add_ent<<endl;//output value
}//end of printmsg function
};//end of struct
int main()
{
Gradebook A[3];
cout<<"Enter the student's name, grade 1 then grade 2\n";
cin>>A[0].student_name>>A[0].grade_1>>A[0].grade_2;
cout<<"Enter the student's name, grade 1 then grade 2\n";
cin>>A[1].student_name>>A[1].grade_1>>A[1].grade_2;
cout<<"Enter the student's name, grade 1 then grade 2\n";
cin>>A[2].student_name>>A[2].grade_1>>A[2].grade_2;
cout<<"Student_Name\t\tGrade_1\t\tGrade_2\t\tADD_ENT"<<endl;
A[0].printmsg();
A[1].printmsg();
A[2].printmsg();
}
|
Idk something similar to this but the loop would end and the headings wouldn't stay there idk if I'm confusing you but you've been helpful so far.
Edit: I got it to work how I'd want it to look, but How do I do that without it continuously looping is my question.
Second edit: I just removed the loop...does the code look fine to you? On a side note...I'm sorry if I've been a slow learner, I have 3 more assignments to do and a major project, is it possible to pm you during the week of my assignments and seek assistance or no?