Formula: Average=Obtain Marks * 100 / Total Marks will be used in this program to find Average of marks in C++
using namespace std;
cout<<"Enter Your Obtained Marks : ";
cout<<"Enter Your Total Marks : ";
cout<<"Your Average is : " <<avg;
This code calculates the average of a student’s marks based on their obtained marks and the total marks of the exam.
Here’s a brief breakdown of what the code does:
#include<iostream> line includes the input/output stream library in the program, which allows us to use input/output functions such as
using namespace std; line allows us to use the standard C++ library without having to specify the
std:: prefix for every function.
int main() function is the entry point of the program. This is where the program begins executing.
avg are declared to store the total marks, obtained marks, and average, respectively.
The program prompts the user to enter their obtained marks by printing the message “Enter Your Obtained Marks : ” on the screen, and then reads the value entered by the user and stores it in the
obt variable using the
The program then prompts the user to enter their total marks and reads the value entered by the user, storing it in the
The average is calculated by dividing the obtained marks by the total marks and storing the result in the
The average is then printed on the screen using the
return 0; statement at the end of the
main() function indicates that the program has completed successfully.