eag*_*mer 0 c++ variables struct variable-assignment
//Program tracks 10 students
//Prompts for first and last names
//Collect 4 grades from each student: final exam, 2 quizzes, and class project
//Report will display names w/ individual scores, class average, and highest grade
//Each students individual grade will be calculated with grade weights
/*Grade Weights
-2 Quizzes @ 15% each
-1 Final Exam @ 20%
-1 Class Project @ 50%
*/
#include<iostream>
using namespace std;
int main()
{
struct goodStudent
{
string fname;
string lname;
double exam;
double quiz1;
double quiz2;
double project;
float realgrd; //(sum of ALL grade weights
};
int pupil = 10; //represents # of students in class
goodStudent student[pupil]; //value of 'pupil' subs as value used to define #elements of student[]
//******Prompt for Student Names:
int i;
for (i = 0; i < pupil; i++)
{
cout << "\n Student " << i+1 << " First Name: ";
cin >>student[i].fname;
cout << "\t Student " << i+1 << " Last Name: ";
cin >>student[i].lname;
}
cout <<"--------------------------------";
//*****Grade Collection and Weights Prompt
int grade;
double quizweight,examweight,projweight,cuml;
for (grade = 0; grade < pupil; grade++)
{
cout <<"\n \t Student"<<" "<< grade+1;
cout << "\n Enter Quiz Grade 1: \n";
cin >>student[grade].quiz1;
cout <<"\n Enter Quiz 2 Grade:\n ";
cin >>student[grade].quiz2;
quizweight = ((student[grade].quiz1)+(student[grade].quiz2))*.30;
cout <<"\n Enter Final Exam Grade:\n ";
cin >> student[grade].exam;
examweight =(student[grade].exam)*.20;
cout <<"\n Enter Project Grade:\n ";
cin >>student[grade].project;
projweight =(student[grade].project)*.50;
//MATH GETS JUMBLED UP HERE.IDK had to do ALOT of conversion and revisions.... ;(
cuml = ((projweight)+(examweight)+(quizweight));
double adjust=((cuml/130))*100;//130 is max pts student can earn across all assignments
cout<<adjust;
adjust=student[grade].realgrd;
cout<<"\n\n\n"<<student[grade].realgrd;
/*
FOR SOME REASON PROGRAM DOESN'T LIKE PUTTING ASSIGNED VALUES INTO ARRAY STRUCT..
fix=student[grade].realgrd;
cout<<"\n\nLet's Try it AGAIN: "<<student[grade].realgrd;
cout<<"\nGrade For Student "<<grade+1<<"\tIs A: "<<fix;
*/
system("PAUSE");
}
}
Run Code Online (Sandbox Code Playgroud)
好.所以我正在尝试为结构数组中的元素赋值.我在将值分配给数组中的元素之前将其打印出来.这是我想要的值,但是当我打印数组以检查是否存在相同的值时,它是一个很长的垃圾编号,如7.6674323e-309.我甚至将struct成员"realgrd"更改为double,float和long变量类型,以查看是否会改变输出,但这不起作用.
我认为你有这条线倒退
adjust=student[grade].realgrd;
Run Code Online (Sandbox Code Playgroud)
你的意思是
student[grade].realgrd = adjust;
Run Code Online (Sandbox Code Playgroud)