Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

i have two questions. 1. how would i creat a program to determine the largest nu

ID: 3625282 • Letter: I

Question

i have two questions.

1. how would i creat a program to determine the largest number out of 15 numbers entered (one at a time). this should be done in a funtion using this prototype

//double larger (doublex, double y)

//make sure i use a for loop expression inside my function.

read the first number of the data set. because this is the only number read to this point, you may assume that it is the largest number so far and call it max.

read the second number and call it num. now compare max and num, and store the larger number into max.now max contains the larger of the two number and so on.



#2. write a program using a funtion and a switch statement. the user should be prompted to enter a number in main. the function is called and the number entered is passed to the funtion. this function parameter will then be used in a switch to discover and print out the number word within the function (for example, 1=one, 2-two, 3-three, etc)

you may choose to limit the number entered by the user to a range. be sure to prompt the user with this range, so you can deal with correct and incorrect numbers entered.



thanks alot guys and this site is the best!!

Explanation / Answer

#include<iostream>
using namespace std;
double larger (double x, double y)
{
       return x>y?x:y;
}
int main()
{
    double max,num;
    cout << "enter first number :" ;
    cin >> num;
    max = num;
    for(int i=1; i<15; i++)
    {
            cout << "Enter number " << (i+1) << " : " ;
            cin >> num;
            max = larger(max,num);
    }
    cout << "Maximum number out of all numbers is " << max <<endl;
    system("pause");
    return 0;
}

#include<iostream>
using namespace std;
void fswitch(int num)
{
     switch(num)
     {
     case 0: cout << "zero" ;
             break;               
     case 1: cout << "one" ;
             break;               
     case 2: cout << "two" ;
             break;               
     case 3: cout << "three" ;
             break;               
     case 4: cout << "four" ;
             break;               
     case 5: cout << "five" ;
             break;               
     case 6: cout << "six" ;
             break;               
     case 7: cout << "seven" ;
             break;               
     case 8: cout << "eight" ;
             break;               
     case 9: cout << "Nine" ;
             break;               
     }
     cout << endl;
               
}
int main()
{
    int num;
    cout << "enter number (in range 0 to 9) :" ;
    cin >> num;
    while(num <0 || num > 9)
    {
              cout << "yoy have to enter number only in range 0 - 9 " <<endl;
               cout << "please enter number :" ;
               cin >> num;
    }
    fswitch(num);
    system("pause");
    return 0;
}