➤ Hello World! in C++
➤ Print Number in C++
➤ Add 2 Numbers C++
➤ Arithmetic Operation
➤ Sum Avg of 3 Number
➤ Area Program in C++
➤ Simple Interest in C++
➤ Find ASCII value in C++
➤ Swap 2 Number in C++
Flow Control Programs
➤ Even-Odd in C++
➤ +ve, -ve, 0 in C++
➤ Vowel-Consonant
➤ Greatest of 3 no.
➤ Check Leap Year
➤ Calculator Program
➤ Reverse a Number
➤ Sum of Natural Number
➤ GCD of 2 Number
➤ LCM of 2 Number
➤ Find Power in C++
➤ Fibonacci Series in C++
➤ Palindrome Number
➤ Find Factorial in C++
➤ Factorial Using Recursion
➤ Prime Number in C++
➤ Prime Number b/w 1-N
Array
➤ Linear Search in C++
➤ Binary Search in C++
Others
➤ Introduction to C++
➤ Data Types in C++
➤ Range of Data Types
➤ Void main, main vs int main
Program description:- Write a C++ program to calculate average marks scored by a student for 3 subjects. Take the marks for those three subjects as input from the end-user, calculate average value and display them.
To calculate the average value of marks scored by the student first we need to calculate the total marks. Then the average value can be calculated as total marks/3.
Assume n1, n2, and n3 are the marks of three subject scored by a student. Then the total marks can be calculated as (n1+n2+n3) and average mark can be calculated as (total marks/3).
Total Mark = n1 + n2 + n3
Average Mark = total_mark / 3
C++ Program to Calculate Average Marks Scored by a Student for 3 Subjects
#include<iostream>
using namespace std;
int main()
{
// declare variables
int n1, n2, n3;
int total;
double avg;
// take input for marks of 3 sub
cout << "Enter Marks of 3 Subjects: ";
cin >> n1 >> n2 >> n3;
// calculate total marks
total = n1 + n2 + n3;
// calculate average mark
avg = total/3;
// display result
cout << "Total Mark = " << total << endl;
cout << "Average Mark = " << avg << endl;
return 0;
}
Output:-
Enter Marks of 3 Subjects: 75 81 84
Total Mark = 240
Average Mark = 80
Enter Marks of 3 Subjects: 49 55 45
Total Mark = 149
Average Mark = 49
The mark for a subject will be an integer number, not the floating-point number therefore we took int data type to store the input value entered by the end-user. The total marks also will be an integer number but the average value can be an integer number or floating-point number therefore we took int data type for the total marks and double data type for the average marks.
To take input from the end-user we have used cin and to display output message to the console window, we used cout.
If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!