153k views
4 votes
Create a program to determine the largest and smallest number out of 15 numbers entered (numbers entered one at a time). This should be done in a function using this prototype: double larger (double x, double y); Make sure you use a for loop expression inside your function. Enter 15 numbers 11 67 99 2 2 6 8 9 25 67 7 55 27 1 1 The largest number is 99

User MarcusH
by
4.0k points

1 Answer

7 votes

Answer:

#include <iostream>

using namespace std;

double larger( double x, double y){

if (x > y){

return x;

} else{

return y;

}

}

int main(){

int n, max = 0;

for (int i =0; i < 15; i++){

cout<< "Enter item"<< i+1 << ": ";

cin>> n;

cout<< "\\";

max = larger( n, max);

}

cout<<"The maximum number is: "<< max;

return 0;

}

Step-by-step explanation:

The C++ program defines the function 'larger' that compares and returns the largest of two numbers. The main program prompts the user for 15 numbers and the larger function is called to return the largest of the fifteen numbers given.

User FishBowlGuy
by
5.0k points