Question

In: Computer Science

Please use c++ and follow the instruction I have written my own code but somehow I'm...

Please use c++ and follow the instruction

I have written my own code but somehow I'm confused during the process I cannot figure out how to finish this lab, I need help.

Write a program that allows user to input four floating-points values and then prints the largest. It must use functions max2 (given below) to determine the largest value. Feel free to use additional functions, but you are not required to do so. Hint: main will call max2 three times to get the work done (i.e., there should be three calls to max2 function).

      double max2(double a, double b)
      {
          double max;

          if (a > b)
              max = a;
          else
              max = b;

          return max;
      }

Follow the format for the sample I/O below. When your code is complete and runs properly, capture the output. Copy and paste both the source code and the output for both test cases.

Test case 1:

Author: Your name
This program allows one to input four values.
It uses function max2 to determine the maximum.

Please enter first value   --> 5.2<Enter>
Please enter second value  --> 1.0<Enter>
Please enter third value   --> 7.1<Enter>
Please enter fourth value  --> 2.5<Enter>
The largest value is 7.1

Test case 2:

Author: Your name
This program allows one to input four values.
It uses function max2 to determine the maximum.

Please enter first value   --> 5.2<Enter>
Please enter second value  --> 7.0<Enter>
Please enter third value   --> 7.0<Enter>
Please enter fourth value  --> 2.5<Enter>
The largest value is 7.0

Here is my code

#include<iostream>
#include<string>

using namespace std;

int max2(double a, double b, double& max);
void displayInfo(double max);

int main()
{
double a, b, c, d;
double number;
int counter;


cout << "Please enter first value ";
cin >> a;

cout << "Please enter second value ";
cin >> b;

cout << "Please enter third value ";
cin >> c;

cout << "Please enter fourth value ";
cin >> d;

displayInfo(max);
  
}

// defination determine the largest value
int max2(double a, double b, double& max)
{
if (a > b)
{
max = a;
}
else
{
max = b;
}
}

// module displayInfo
void displayInfo(double max)
{
cout << "The largest value is "<< max << "\n";
}

Solutions

Expert Solution

Source Code:

Output:

Code in text format (See above images of code for indentation):

#include<iostream>
using namespace std;
/*function prototypes*/
double max2(double a,double b);
void displayInfo(double max);
/*main function*/
int main()
{
   /*variables*/
   double a, b, c, d;
   double n1,n2;
   /*read 4 floating point numbers*/
   cout << "Please enter first value ";
   cin >> a;
   cout << "Please enter second value ";
   cin >> b;
   cout << "Please enter third value ";
   cin >> c;
   cout << "Please enter fourth value ";
   cin >> d;
   /*function calls*/
   /*find max in a and b and store in n1*/
   n1=max2(a,b);
   /*find max in c and d and store in n2*/
   n2=max2(c,d);
   /*now find max in n1 and n2 and store in n1 is maximum*/
   n1=max2(n1,n2);
   /*function call to display maximum*/
   displayInfo(n1);
}

/*function defination determine the largest value*/
double max2(double a, double b)
{
   double max;
   /*check for max and assign maximum to max*/
   if (a > b)
       max = a;
   else
   max = b;
   return max;
}

/*module displayInfo*/
void displayInfo(double max)
{
cout << "The largest value is "<< max << "\n";
}


Related Solutions

Please use c++ and follow the instruction, I really want to fully understand this question and...
Please use c++ and follow the instruction, I really want to fully understand this question and I will use your code to check where I made mistake (Do not skip steps). I have written my own code which has tons of errors, and I am so confused about this lab. I need help. Lab 6.4 – C++ and Functions – Math Test Critical Review A value-returning function is a function that returns a value back to the part of the...
I'm having a very hard time getting this c++ code to work. I have attached my...
I'm having a very hard time getting this c++ code to work. I have attached my code and the instructions. CODE: #include using namespace std; void printWelcome(string movieName, string rating, int startHour, int startMinute, char ampm); //menu function //constants const double TICKET_PRICE = 9.95; const double TAX_RATE = 0.095; const bool AVAILABLE = true; const bool UNAVAILABLE = false; int subTotal,taxAdded, totalCost; // bool checkAvailability( int tickets, int& seatingLeft){ //checks ticket availability while(tickets > 0 || tickets <= 200) //valid...
I'm getting an error with my code on my EvenDemo class. I am supposed to have...
I'm getting an error with my code on my EvenDemo class. I am supposed to have two classes, Event and Event Demo. Below is my code.  What is a better way for me to write this? //******************************************************** // Event Class code //******************************************************** package java1; import java.util.Scanner; public class Event {    public final static double lowerPricePerGuest = 32.00;    public final static double higherPricePerGuest = 35.00;    public final static int cutOffValue = 50;    public boolean largeEvent;    private String...
So I have written a code for it but i just have a problem with the...
So I have written a code for it but i just have a problem with the output. For the month with the highest temperature and lowest temperature, my code starts at 0 instead of 1. For example if I input that month 1 had a high of 20 and low of -10, and every other month had much warmer weather than that, it should say "The month with the lowest temperature is 1" but instead it says "The month with...
This is my C language code. I have some problems with the linked list. I can't...
This is my C language code. I have some problems with the linked list. I can't store the current. After current = temp, I don't know how to move to the next node. current = current-> next keeps making current into NULL. #include #include #include #include struct node{int data; struct node *next;}; int main() {     struct node *head, *current, *temp, *trash;     srand(time(0));     int randNumber = rand()%51;     if(randNumber != 49)     {         temp = (struct node*)malloc(sizeof(struct node));         current = (struct node*)malloc(sizeof(struct node));...
I have an unexpected indent with my python code. please find out whats wrong with my...
I have an unexpected indent with my python code. please find out whats wrong with my code and run it to show that it works here is the code : def main(): lis = inputData() customerType = convertAcct2String(lis[0]) bushCost = getBushCost(lis[0],int(lis[1],10)) flowerCost = getFlowerBedCost(int(lis[2],10),int(lis[3],10)) fertiCost = getFertilCost(int(lis[4],10)) totalCost = calculateBill(bushCost,fertiCost,flowerCost) printReciept(customerType,totalCost,bushCost,fertiCost,flowerCost) def inputData(): account, number_of_bushes,flower_bed_length,flower_bed_width,lawn_square_footage = input("Please enter values").split() return [account, number_of_bushes,flower_bed_length,flower_bed_width,lawn_square_footage] def convertAcct2String(accountType): if accountType== "P": return "Preferred" elif accountType == "R": return "Regular" elif accountType == "N": return...
I need code written in java for one of my projects the instructions are Write a...
I need code written in java for one of my projects the instructions are Write a program that interacts with the user via the console and lets them choose options from a food menu by using the associated item number. It is expected that your program builds an <orderString> representing the food order to be displayed at the end. (See Sample Run Below). Please note: Each student is required to develop their own custom menus, with unique food categories, items...
I'm having trouble with validating this html code. Whenever I used my validator, it says I...
I'm having trouble with validating this html code. Whenever I used my validator, it says I have a stray end tag: (tbody) from line 122 to 123. It's the last few lines. Thanks and Ill thumbs up whoever can help solve my problem. Here's my code: <!DOCTYPE html> <html lang="en"> <head> <title>L7 Temperatures Fields</title> <!--    Name:    BlackBoard Username:    Filename: (items left blank for bb reasons    Class Section: (blank)    Purpose: Making a table to demonstrate my...
I have written code in C programming that checks where the command line arguments are floats...
I have written code in C programming that checks where the command line arguments are floats or not. For example, if I type "./math 1 1 0 0 2.5 3" in the terminal, my program realizes they are all floats but if I type "./math 1 1 0 0 2.5 g", it recognizes that not all arguments are floats and gives an error message. I want to take my code further such that after typing in "./math 1 1 0...
I am having trouble with a C++ code that I'm working on. It is a spell...
I am having trouble with a C++ code that I'm working on. It is a spell checker program. It needs to compare two arrays, a dictionary, and an array with misspelled strings that are compared to the strings in the dictionary. the strings that are in the second array that is not in the Dictionary are assumed to be misspelled. All of the strings in the dictionary are lowercase without any extra characters so the strings that are passed into...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT