### Should we use do while loops, nested ifs in theis question??

Write a program that uses nested loops to read the marks of 5 students in 3 subjects and calculate
their total marks and average.

If you can...do this question for me please... :)

ok im posting the codes -------An sorri i was so impatient to post ...
 ``123456789101112131415161718192021222324252627282930313233343536`` ``````#include using namespace std; int main() { float s1, s2, s3; //3 subjects double ave, tmrk; //average score + total marks char choi; //holding Y or N input for 5 students do { //input 3 scores cout<<"Enter the marks of the 3 subjects please:-\n"; cin>>s1; cin>>s2; cin>>s3; //calculating total marks tmrk = (s1 + s2 + s3); cout<<"The total marks of the student is "<>choi; } while (choi == 'Y' || choi == 'y'); return 0; }``````

Last edited on
Your code appears correct in case you only want to store the values of marks , average marks and total marks temporarily to display.
If you know the number of loops -iterations- (5x3=15)you can use for loop instead
of while or do-while.

 ``12345678910111213141516171819202122232425262728293031323334353637`` ``````//marks.cpp //Program that uses nested loops to read the marks //of 5 students in 3 subjects and calculate their total //marks and average. #include using std::cout; using std::cin; using std::endl; int main(){ const int STUDENTS=5; const int SUBJECTS=3; double subjects[STUDENTS][SUBJECTS]={}; double average[STUDENTS]={0}; for(int i=0;i>subjects[i][j]; average[i]+=subjects[i][j]; //calculating total marks }//end inner for cout<<"\nThe total marks of student "<

 ``` Eyenrique-MacBook-Pro:Help Eyenrique\$ ./marks Student 1 Enter the mark of subject 1 :1 Enter the mark of subject 2 :2 Enter the mark of subject 3 :3 The total marks of student 1 is: 6 The average marks for student 1 is: 2 Student 2 Enter the mark of subject 1 :2 Enter the mark of subject 2 :3 Enter the mark of subject 3 :4 The total marks of student 2 is: 9 The average marks for student 2 is: 3 Student 3 Enter the mark of subject 1 :3 Enter the mark of subject 2 :5 Enter the mark of subject 3 :7 The total marks of student 3 is: 15 The average marks for student 3 is: 5 Student 4 Enter the mark of subject 1 :0 Enter the mark of subject 2 :0 Enter the mark of subject 3 :0 The total marks of student 4 is: 0 The average marks for student 4 is: 0 Student 5 Enter the mark of subject 1 :1 Enter the mark of subject 2 :2 Enter the mark of subject 3 :1 The total marks of student 5 is: 4 The average marks for student 5 is: 1.33333 ```
Thank you...we had to use nested FOR loop...i've used WHILE loop...which is incorrect. Thanks for the guidelines.
Topic archived. No new replies allowed.