what error??

xD xD
Last edited on
with the assignment operator =
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
struct student
{
   int snum;
   float exam;
   float quiz;
   float progass;
   float labex;
   float test;
};


for(i = 0; i < sentinel; i++)
    {
          cout << "Student Number >> ";
          cin >> (WHAT SHOULD I ENTER HERE TO ASSIGN THE VALUE snum???) >> endl;
snum. The user will then enter the int value which snum will then hold.
See the section on how to access members. It's worth nothing you can't just modify snum; you need to create an instance of student and modify it's snum.

http://www.cplusplus.com/doc/tutorial/structures/
buffbill: what command i should enter there so that the prog will prompt me to enter the number...

zhuge: i already browse that site many time still don't understand.. i even copy and paste the program and just edit the variable but still error keep coming out. The original had no error but when i just edit the name of variable ONLY error came out..
Normally, you'd assign values to basic data types like "int", right? So for example, this would assign something to an integer variable called "stud_snum"

1
2
3
          int stud_snum; // here you say, that you have a variable "stud_snum" of an number type
          cout << "Student Number >> ";
          cin >> stud_snum >> endl;


so far so good. But if you got more than one variable that all are somehow should be kept together, like "stud_snum", "stud_exam", "stud_quiz" and so on... this gets confusing really quickly.

1
2
3
4
5
6
          int stud_snum;
          int stud_exam;
          int stud_quiz; // woah.. this is not very comfertable
          cout << "Student Number >> ";
          cin >> stud_snum >> endl;
          ...


So you introduce a new type that you can use instead of "just a number". This is your "struct student". But this is only a type like "int". It's not a variable.

This means, you also need to declare a variable of the new type. Just like you declared "stud_snum"

1
2
3
4
5
6
7
8
9
10
11
12
struct student
{
   int snum; // here you say what numbers belong to every "student"
   float exam;
   float quiz;
...
};
...
          student stud; // here you have a student variable called "stud". Within the student are all the numbers
          cout << "Student Number >> ";
          cin >> stud.snum >> endl; // here you say that you want to use the number "snum" from the student
          ...



Ciao, Imi.
Last edited on
#define SIZE 10
struct student
{
int snum;
float exam;
float quiz;
float progass;
float labex;
float test;
};

int main()
{
int i =0;
struct student stuArray[SIZE];

for(i=0;i<SIZE;i++)
{
cout << "Enter student number: ";
cin >> stuArray[i].snum;
cout << "Enter exam code :";
...
.....
}

for(i=0;i<SIZE;i++)
{
cout << stuArray[i].snum;
..
....
}
return 0;
}
yo dude i know what's im wrong.. after the cin process i go add endl at the end.. =.= no wonder error keep on poping out. thanks for your all advice
errm i am suppose to enter the marks for students inside an array of structure and total their marks and assign grade to it..
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include<iostream>
#include<iomanip>
using namespace std;

void cal();
void grade();

const int sentinel = 1000;

struct student
{
   int snum;
   float exam;
   float quiz;
   float progass;
   float labex;
   float test;
};

int main()
{
    int i,count = 0;
    float rslt;
    char a,y;
    struct student result[sentinel];

    for(i = 0; i < sentinel; i++)
    {    
          cout << "\nEnter Y/y to enter the data entries or N/n to terminate the data entries " ;
          cin >> a;
          if (a == 'N' || a == 'n' )
          break;
          else if (a == 'y' || a == 'Y')
          cout << "Student Number: ";
          cin >> result[i].snum;
          cout << "==================================================================" << endl;
          cout << "Marks for exam is ";
          cin >> result[i].exam;
          cout << "Marks for quiz is ";
          cin >> result[i].quiz;
          cout << "Marks for programming assignment is ";
          cin >> result[i].progass;
          cout << "Marks for lab exercise is ";
          cin >> result[i].labex;
          cout << "Marks for test is ";
          cin >> result[i].test;
          void cal();
          void grade();
          count++;
    }
    cout << setiosflags(ios::left);
    for(i = 0; i < count; i++)
    {
      cout << setw(7) << result[i].snum
           << setw(3) << result[i].exam
           << setw(3) << result[i].quiz
           << setw(3) << result[i].progass
           << setw(3) << result[i].labex
           << setw(3) << result[i].test
           << endl;
    }   
           
    
    
    
    
    
    system("pause");
    return 0;
}

void cal()
{    
     int i;
     float rslt;
     struct student result[sentinel];
     const float E = 0.6, Q = 0.1, PG = 0.1, LE = 0.1, T = 0.1;
     rslt = (result[i].exam*E)+(result[i].quiz*Q)+(result[i].progass*PG)+(result[i].labex*LE)+(result[i].test*T);
     return ;
}



void grade()
{    
     float rslt;
     int i;
     for(i = 0; i < 100; i++)
     {
        if (i>=80.0 || i<=100)
        cout << "Final Score is >> " << rslt << "\nGrade is A " << endl;
        else if (i>=70 || i<=79.9)
        cout << "Final Score is >> " << rslt << "\nGrade is B " << endl;
        else if (i>=60 || i<=69.9)
        cout << "Final Score is >> " << rslt << "\nGrade is C " << endl;
        else if (i>=50 || i<=59.9)
        cout << "Final Score is >> " << rslt << "\nGrade is D " << endl;
        else if (i>=0 || i<=49.9)
        cout << "Final Score is >> " << rslt << "\nGrade is F " << endl;
     }
     return;
}



The point is.. my fuction to calculate and output the grade and final score is not working.. can anybody help???

final score = exam*0.6 + quiz*0.1 + prog*0.1 + lab*0.1 + test*0.1 which will result the score to determine the grade
Last edited on
Hi jt1991, I have a solution for you, please accept private messages and I can give it to you!
// MondO
Last edited on
Two things about this thread that irritate me a lot:
1. OP deleting [the contents of] his post and replacing it with meaningless rubbish, meaning that no-one else with the same error he had can not find this thread and end their problem
2.
Hi jt1991, I have a solution for you, please accept private messages and I can give it to you!

Please do not give people solutions. Besides that, OP almost has it right.
Topic archived. No new replies allowed.