-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC++ Loop while loop sum and average.cpp
More file actions
42 lines (32 loc) · 1.03 KB
/
C++ Loop while loop sum and average.cpp
File metadata and controls
42 lines (32 loc) · 1.03 KB
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
40
41
42
/**
[AUTHOR]: Saddam Arbaa
[Email] : <saddamarbaas@gmail.com>
while examples in C++
This example will print the average grade for N student
*/
#include <iostream>
using namespace std;
// the Driver Code
int main()
{
int i = 1; // counter
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;
while (i <= N)
{
// asking user to enter variable n
cout << "Enter grade for student "<<i<< " : ";
cin >> grade;
sum = sum + grade; // calculating the sum
i = i + 1; // increment counter by 1
}
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 */