samedi 24 avril 2021

A C++ Program that reads the marks obtained of ten students out of 100. It also computes the average; lowest and highest marks

A C++ Program that reads the marks obtained of ten students out of 100. It also computes the average; lowest and highest marks. Then shows the difference of marks of every student from the average marks.

Here goes the code written by me for this problem. But when I run the program I am getting value of average and low marks as 0 and also the difference of average and marks obtained is not coming the same what I needed it to be. Can someone explain me that where I am lacking, I am a novice in programming.

#include<iostream>
using namespace std;

int main(){
int marks[10],avg=0,high,low;
cout<<"Enter the marks of 10 students:";
for(int i=0;i<10;i++){
  cin>>marks[i];
  if(marks[i]>marks[i+1]){
    low=marks[i+1];
  }
  else 
  {
    low=marks[i];
  }
  if(marks[i]>marks[i+1]){
    high=marks[i];
  }
  else 
  {
    high=marks[i+1];
  }
  
  avg=avg+(marks[i])/100;
}
for(int i=0;i<10;i++){
cout<<"Marks obtained by "<<i+1<<" student:"<<marks[i]<<endl;
  cout<<"Difference of marks of student "<<i+1<<" with average marks:";
  
  if((avg-marks[i])>0){cout<<avg-marks[i];}
  else{cout<<marks[i]-avg;}
  cout<<endl<<endl;
  }
cout<<"Lowest marks:"<<low<<endl;
cout<<"Highest marks:"<<high<<endl;
cout<<"Average marks:"<<avg<<endl;
return 0;
}

Aucun commentaire:

Enregistrer un commentaire