-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemo.arrayIntro.cpp
More file actions
50 lines (40 loc) · 1.28 KB
/
Copy pathDemo.arrayIntro.cpp
File metadata and controls
50 lines (40 loc) · 1.28 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
43
44
45
46
47
48
49
50
//************************************************************************
// Author: Rolando Carreon
// Date: apr 8 2025
// Language: C++
// Assignment: Array Intro Demo
// Description: Hello World Program
//************************************************************************
#include<iostream>
using namespace std;
int main()
{
// declare local variables
int grades[3];
int sum = 0;
float average;
int highest;
// get the grades from the user and populate the array
for (int i = 0; i < 3; i++)
{
cout << "Enter the grade for student " << i + 1 << ": ";
cin >> grades[i];
sum += grades[i]; // add the grade to the total sum
}
// calculate and display the average grade
// make sure to use floatting-point math for the average
average = sum / 3.0;
cout << "The average grade is: " << average << endl;
// find a display the highest grade
highest = grades[0]; // assume the 1st grade is the highest
// iterate through the array looking for a higher grade
for (int i = 1; i < 3; i++)
{
if (grades[i] > highest)
{
highest = grades[i]; // update the highest grade
}
}
cout << "The highest grade is: " << highest << endl;
return 0;
}