New to programming

Understanding if else Statements

Summary
In this lab, you complete a prewritten C++ program that computes the largest and smallest of three integer values.

Instructions
Two variables named largest and smallest are declared for you. Use these variables to store the largest and smallest of the three integer values. You must decide what other variables you will need and initialize them if appropriate.
Your program should prompt the user to enter 3 integers.
Write the rest of the program using assignment statements, if statements, or if else statements as appropriate. There are comments in the code that tell you where you should write your statements. The output statements are written for you.
Execute the program by clicking the Run button at the bottom of the screen.
Using the input of -50, 53, 78, your output should be:

The largest value is 78

The smallest value is -50
> In this lab, you complete a prewritten C++ program that computes the largest and smallest of three integer values.
OK, so where is it?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// LargeSmall.cpp - This program calculates the largest and smallest of three integer values. 

#include <iostream>
using namespace std;
int main()
{
   // This is the work done in the housekeeping() function
   // Declare and initialize variables here
   int largest;	// Largest of the three values
   int smallest;   // Smallest of the three values
   
   // Prompt the user to enter 3 integer values

   // Write assignment, add conditional statements here as appropriate
			
   // This is the work done in the endOfJob() function
   // Output largest and smallest number. 
   cout << "The largest value is " << largest << endl;
   cout << "The smallest value is " << smallest << endl;
   return 0; 
} 

we want to help you. to do that, you need to ask a question and post code. You have the code part now, but no question, just a copy of an assignment.

I mean, to get you started...
read a number.
set largest and smallest both = that number.
read another number.
if > largest, update largest.
if < smallest, update smallest.
do that once more for the third value.

this forum is here to help, but not do it for you.
Last edited on
Topic archived. No new replies allowed.