166k views
3 votes
Find extreme value. C++

Assign variable biggestVal with the largest value of 5 positive floating-point values read from input.
Ex: If the input is 17.9 8.7 1.2 17.7 9.2, then the output is:
17.9
Note:
--The first value read is the largest value seen so far.
--All floating-point values are of type double
------------------------
#include
#include
using namespace std;

int main() {
double inputVal;
double biggestVal;
int i;

/* Your code goes here */

cout << biggestVal << endl;

return 0;
}

User Vvolkov
by
7.3k points

1 Answer

1 vote

Answer:

Here's the updated code with comments and the implementation to find the largest value:

#include <iostream>

#include <iomanip>

using namespace std;

int main() {

double inputVal;

double biggestVal;

int i;

Step-by-step explanation:

// Read the first input value and assign it to biggestVal

cin >> biggestVal;

// Loop through the remaining input values

for (i = 1; i < 5; i++) {

cin >> inputVal;

// Check if the new value is greater than the current biggestVal

if (inputVal > biggestVal) {

biggestVal = inputVal;

}

}

// Output the largest value

cout << fixed << setprecision(1) << biggestVal << endl;

return 0;

User Kevin Py
by
7.6k points