-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC++ Loop For loop average.cpp
More file actions
39 lines (30 loc) · 991 Bytes
/
C++ Loop For loop average.cpp
File metadata and controls
39 lines (30 loc) · 991 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
[AUTHOR]: Saddam Arbaa
[Email] : <saddamarbaas@gmail.com>
for loop examples in C++
This example will print the average grade for N student
*/
#include <iostream>
using namespace std;
// the Driver Code
int main()
{
float N; // N variable for number of student
float sum = 0.0; // sum variable and give value 0
float average , grade; // average ,grade variable
// first ask user for number of student
cout << "Enter number of students : ";
cin >> N;
for(int i = 1; i <= N; i++)
{
// asking user to enter variable n
cout << "Enter grade for student "<<i<< " : ";
cin >> grade;
sum = sum + grade; // calculating the sum
}
average = sum / N; // calculating the average with type casting sum to float
// print sum and average
cout <<"the sum is : "<<sum<< endl;
cout <<"the average : = "<<average<< endl;
return 0;// signal to operating system everything works fine
}/** End of main function */