Question & Answer: ark. If the mark is less than 0 or greater than 100, the program will print a message stating the mark entered is…..

Q7 Selection within a loop/break/continue Using do-while structure, write a program that continuously requests the user to enter a mark. If the mark is less than O or greater than 100, the program will print a message stating the mark entered is invalid; otherwise, the mark will be added to the total. When a mark of 999 (sentinel) is entered, the program should end the loop and display the average of the valid marks entered in two decimal points. Enter a mark (enter 999 to exit): 100 Enter a mark (enter 999 to exit): 101 An invalid mark has been entered! Please reenter a valid mark. Enter a mark (enter 999 to exit):-2 An invalid mark has been entered! Please reenter a valid mark. Enter a mark (enter 999 to exit):50 Enter a mark (enter 999 to exit):999 you have chosed to end the program The average of the valid marks entered is: 75.00 Dev C++

Selection within a loop/break/continue Using do-while structure, write a program that continuously requests the user to enter a mark. If the mark is less than 0 or greater than 100, the program will print a message stating the mark entered is invalid: otherwise, the mark will be added to the total. When a mark of 999 (sentinel) is entered, the program should end the loop and display the average of the valid marks entered in two decimal points. Enter a mark (enter 999 to exit): 100 Enter a mark (enter 999 to exit): 101 An invalid mark has been entered! Please reenter a valid mark. Enter a mark (enter 999 to exit): -2 An invalid mark has been entered! Please reenter a valid mark. Enter a mark (enter 999 to exit): 50 Enter a mark (enter 999 to exit): 999 you have choose to end the program The average of the valid marks entered is: 75.00

Expert Answer

 

Answer :-

This is the code for your question

#include<iostream>

#include<iomanip>

using namespace std;

int main(){

int m,c=0;

float total;

do{

cout<<“Enter marks(999 to exit:”;

cin>>m;

cout<<endl;

if(m==999){

cout<<“You have chosed to end the program.”<<endl;

break;

}

else if(m>=0&&m<=100){

total+=m;

c++;

}

else

cout<<“An invalid mark has been entered: Please reenter valid marks.”<<endl;

}while(m!=999);

total/=c;

cout<<“The average of the valid marks:”<<fixed<<setprecision(2)<<total;

return 0;

}

Still stressed from student homework?
Get quality assistance from academic writers!