Skip to content
Loading
  • Abdalla Elawad
    0
    Hello Ankit Sharma
     
    yes different , here enter (n) of students (n number of studen) and number of Marks (x marks ) and print sum of marks to each student .
     
    thank you 
    0
  • Ankit Sharma
    0
    Hi,
     
    You can modify the existing code to get this output.
     
    just put a for loop for number of student outside the for loop to calculate marks.
    1. int i,j, numberofstudent;  
    2.   
    3.   for (j = 1; j <= numberofstudent; j++)  
    4.   {  
    5.       cout << "Enter the marks for student" << endl;  
    6.   
    7.       for (i = 1; i <= 5; i++)  
    8.       {  
    9.           cout << " subject" << i << ":" << endl;  
    10.           cin >> score;  
    11.           if (score < 0 || score > 100)  
    12.           {  
    13.               cout << "Enter valid score" << endl;  
    14.               i--;  
    15.               continue;  
    16.           }  
    17.           total += score;  
    18.           cout << total << endl;  
    19.       }  
    20.   }  
     This will give you total marks for each student separately.
     
    Please try and let me know if it works for you. 
    0
  • Abdalla Elawad
    0
    ANKIT 
     
    itsn't solve , pls write complete code , loop doesn't work . 
    0
  • Ankit Sharma
    0
    Hi,
    you just need to read value for numbner of student from user. this is the least you can do from yourself
     
    1. int i,j, numberofstudent;    
    2.     cout<<"enter numer of student"<
    3.     cin>>numberofstudent;    
    4.     
    5.   for (j = 1; j <= numberofstudent; j++)    
    6.   {    
    7.       cout << "Enter the marks for student" << endl;    
    8.     
    9.       for (i = 1; i <= 5; i++)    
    10.       {    
    11.           cout << " subject" << i << ":" << endl;    
    12.           cin >> score;    
    13.           if (score < 0 || score > 100)    
    14.           {    
    15.               cout << "Enter valid score" << endl;    
    16.               i--;    
    17.               continue;    
    18.           }    
    19.           total += score;    
    20.           cout << total << endl;    
    21.       }    
    22.   }   
     
    0
  • Abdalla Elawad
    0
    Erorr in sumatin , itsn't sum to each , save first sum and sum to next student
    do it please 
    0
  • Ankit Sharma
    0
    Hi,
     
    Your reply is not clear to me?
     
    Do you want sumof marks of each student or you want sum of marks of all students? 
    0
  • Abdalla Elawad
    0
    Each Sum of Marks
     like below :
     
    10
    30
    20
    sum of mark = 60
     
    20
    20
    50
    sum of mark = 90 
    0
  • Ankit Sharma
    0
    This means sum of marks for each student. This is what i am doing in below code. The variable total will give you the sum of marks of one student in all the subjects. 
    1. int i,j, numberofstudent;      
    2.     cout<<"enter numer of student"<
    3.     cin>>numberofstudent;      
    4.       
    5.   for (j = 1; j <= numberofstudent; j++)      
    6.   {      
    7.       int total =0;  
    8.       int score=0;  
    9.       cout << "Enter the marks for student" << endl;      
    10.       
    11.       for (i = 1; i <= 5; i++)      
    12.       {      
    13.           cout << " subject" << i << ":" << endl;      
    14.           cin >> score;      
    15.           if (score < 0 || score > 100)      
    16.           {      
    17.               cout << "Enter valid score" << endl;      
    18.               i--;      
    19.               continue;      
    20.           }      
    21.           total += score;      
    22.           cout << total << endl;      
    23.       }      
    24.   }     
    0