# I need help plzz :(

• 11-05-2009
Kawaii JoJo
I need help plzz :(
We have 20 Students from different levels (4290**** , 4280**** , 4270**** , 4260****) Every ID will start with one of those numbers .. (The ID cosist of 8 digits )
And their Grades in 1 subject..

It is supposed to print :

1- Students ID and their Grades.

2- Student ID that got the highest grade and the lowest grade and their and the ID Second two numbers starting from the left for the two students.

3- The number of students got grades equal to Average or higher.

4- The number of students got grades smaller than the Average.

5- The number os Students from each Level .

This is the program I wrote :

Code:

```#include <iostream> #include <conio> void main() { int numberOfStudents [20] ; int score[100]; char grade; int ID ; int i , j ; for( i=0 ; i<20 ;i++) {     cout << "Enter Student "  << (i+1) << "  ID " ;   cin>> ID;   cout<< "Enter the score ";   cin>>score[j]; for( j=0;j<20;j++)     {     if(score[j]>=90)         grade='A';     else if(score[j]>=80)         grade='B';     else if (score[j]>=70)         grade='C';     else if (score[j]>=60)         grade='D';     else         grade='F';     }   }     cout<<"Student "<<(i+1)<<" score is = "<<(score[j])     <<" and grade assigned is "<<grade<<endl;   getch (); }```
I don't know how to complete it .. ><
Any Help would be Gratefully Appreciated !!
• 11-05-2009
Dino
Your use of variable j in this segment of code is incorrect:
Code:

```for( i=0 ; i<20 ;i++) {     cout << "Enter Student "  << (i+1) << "  ID " ;   cin>> ID;   cout<< "Enter the score ";   cin>>score[j]; . . .```
• 11-05-2009
Dino
Also, you have 20 students and 100 scores. Why?
• 11-05-2009
bleuz
Where are you suppose to get the grades from? are you inputting them from a file?

Do you have AIM or anything to chat. I have some extra time right now if you need help
• 11-05-2009
this is for the first part

Code:

``` #include <iostream> using namespace std; int main() {     int ID [20];     int score [20];     int i,j;     for (i=0;i<20;i++)     {         cout<<"Enter Student "<< i+1<< " ID: "<<endl;         cin>> ID[i];         cout<<"Enter Studet " << i+1<< "score: "<<endl;         cin>> score[i];     }     for(j=0;j<20;j++)     {         if (score[j]<=100 && score[j]>=90)         cout<<ID[j]<< "got " <<'A'<< endl;         else         if (score[j]<90 && score[j]>=80)         cout<<ID[j]<< "got " <<'B'<<endl;         else         if (score[j]<80 && score[j]>=70)         cout<<ID[j]<< "got " <<'C'<<endl;         else         if (score[j]<70 && score[j]>=60)         cout<<ID[j]<< "got " <<'D'<<endl;         else         if (score[j]<60)         cout<<ID[j]<< "got " <<'F'<<endl;     }     return 0; }```
• 11-05-2009
*to calculate the average:
in the first for loop sum+=score[i];

then in the end of the program

float Avg= sum/20;
cout<<"average = "<<Avg;

*for the lowest and highest:
declared a new variables
low=score[0];
high=score[0];

then make another for loop

Code:

``` for(int n=1; n<20; n++) {       if ( score[n]>low)       low=score[n];       if (score[n]<high)       high=score[n]; }```
i hope it is will help u... and if u have any question u are more than welcome...
• 11-05-2009
bleuz
ladybird we want people to try to solve the problem on their own. We do not want to simply tell them what to do, they will never learn this way. And I'm assuming this is homework so we are not here to do homework for people.

and if nothing else explain why he needs to be making these changes so he can understand on a logical level how they work
• 11-06-2009
Kawaii JoJo
THX ladybird u helped me ALOT.. :D
I really appreciate it ..

This is the program after correction and I add things :

Code:

```#include <iostream> #include <conio> int main() {     int ID [20];     int score [20];     int i,j;     int low=score[0];     int high=score[0];     int sum=0 ;     int d1 , d2 , d3 ;     int sum1 , sum2 , sum3 , sum4, z , q ;     float Avg ;     for (i=0;i<20;i++)     {         cout<<"Enter Student "<< (i+1) << " ID: "<<endl;         cin>> ID[i];         cout<<"Enter Studet " << (i+1) << "score: "<<endl;         cin>> score[i];         sum+=score[i];         d1=ID[i]/100000000;         ID[i]%=100000000;         d2=ID[i]/10000000;         ID[i]%=10000000;         d3=ID[i]/1000000;         ID[i]%=1000000;         if(d3==9)         sum1+=i;         if(d3==8)         sum2+=i;         if(d3==7)         sum3+=i;         if(d3==6)         sum4+=i;     }     for(j=0;j<20;j++)     {         if (score[j]<=100 && score[j]>=90)         cout<<"Student :" << ID[j] <<" score is " <<(score[j])         << " and the grade is " <<'A'<< endl;         else         if (score[j]<90 && score[j]>=80)         cout<<"Student :" << ID[j] << " score is " << (score[j])         << " and the grade is  " <<'B'<<endl;         else         if (score[j]<80 && score[j]>=70)         cout<<"Student :" << ID[j]<< " score is " << (score[j])         << " and the grade is "  <<'C'<<endl;         else         if (score[j]<70 && score[j]>=60)         cout<<"Student :" << ID[j]<< " score is " << (score[j])         << "and the grade is " <<'D'<<endl;         else         if (score[j]<60)         cout<<"student :" <<ID[j] << " score is " << (score[j])         << " and the grade is " <<'F'<<endl;             Avg= sum/20;         if ( score[j]>=Avg )         z+=i;         else         q+=i;   }     for(int n=1; n<20; n++)   {       if ( score[n]>high)       high=score[n];       if (score[n]<low)       low=score[n];   } cout<< "The Highest score is :" << high << " Assigned to " <<ID[j] << " Student" <<endl;   cout<< "The lowest score is :" << low << " Assigned to " << ID[j] << " Student" <<endl;   cout<< endl << endl;   cout<<"Average = "<<Avg << endl;   cout<< "The number of students that got score bigger than or egual Avg =" << z << endl;   cout<< "The number of students that got score less than Avg ="<< q << endl;   cout<< "The number of students from level 29 are :" << sum1 << endl;   cout<< "The number of students from level 28 are :" << sum2 << endl;   cout<< "The number os students from level 27 are :" << sum3 << endl;   cout<< "The number of students from level 26 are :" << sum4 << endl;   getch ();   return 0; }```
The problem is the Outputs in my program are garbage .. so I don't if its true or not .. (If there is a way to correct it tell me plz ) ..

I want to know how many students from each level .. Is there any mistakes ??
• 11-06-2009
U R Welcome ;)

I don't understand why u use #include<conio> ???

there is no such file called conio in the compiler which I use...!!
• 11-06-2009
gamer4life687
Code:

`int sum1 , sum2 , sum3 , sum4, z , q ;`
What do you think this does?

output sum1 sum2 sum3 immediately after this line
and take it from there...
• 11-06-2009
darren78
Quote:

U R Welcome ;)

I don't understand why u use #include<conio> ???

there is no such file called conio in the compiler which I use...!!

It's the header for getch() which is a C function. I would get rid of getch and conio and use maybe system("pause") instead.
• 11-06-2009