I need help plzz :(

This is a discussion on I need help plzz :( within the C++ Programming forums, part of the General Programming Boards category; We have 20 Students from different levels (4290**** , 4280**** , 4270**** , 4260****) Every ID will start with one ...

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    9

    Unhappy 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 !!

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    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];
    . . .
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  3. #3
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    Also, you have 20 students and 100 scores. Why?
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  4. #4
    Registered User
    Join Date
    Sep 2009
    Posts
    68
    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

  5. #5
    Registered User
    Join Date
    Nov 2009
    Posts
    17
    correct your code
    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;
    }
    Last edited by ladybird__86; 11-05-2009 at 05:48 PM.

  6. #6
    Registered User
    Join Date
    Nov 2009
    Posts
    17
    *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...

  7. #7
    Registered User
    Join Date
    Sep 2009
    Posts
    68
    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

  8. #8
    Registered User
    Join Date
    May 2009
    Posts
    9
    THX ladybird u helped me ALOT..
    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 ??

  9. #9
    Registered User
    Join Date
    Nov 2009
    Posts
    17
    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...!!

  10. #10
    Registered User
    Join Date
    Jun 2002
    Posts
    230
    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...
    C++ Rules!!!!
    ------------
    Microsoft Visual Studio .NET Enterprise

  11. #11
    Registered User
    Join Date
    Feb 2009
    Posts
    329
    Quote Originally Posted by ladybird__86 View Post
    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.

  12. #12
    Registered User
    Join Date
    Nov 2009
    Posts
    17
    Quote Originally Posted by darren78 View Post
    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.
    oh OK i did not use C language, because that i don't know
    thank you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. plzz need help with remove() method
    By babyray in forum C++ Programming
    Replies: 2
    Last Post: 05-09-2009, 10:34 AM
  2. help me out plzz!!
    By salmanriaz in forum Game Programming
    Replies: 11
    Last Post: 03-20-2009, 09:56 AM
  3. beginner plzz help urgent
    By sara101 in forum C Programming
    Replies: 11
    Last Post: 01-14-2007, 09:38 PM
  4. Plzz help problem with strings
    By UltimoFX in forum C Programming
    Replies: 5
    Last Post: 04-14-2003, 08:06 PM
  5. need help , plzz
    By kfatima in forum C Programming
    Replies: 1
    Last Post: 10-11-2002, 09:19 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21