English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I need help. I need to write a program with functions that gives the following output: ( I will use the numbers as examples (they must be values between 1 and 200))

The three numbers are:
150 1 79
This group is valid:
largest is: 150
smallest is: 1
range is:149
the range is 100 or more

another example output if the numbers arent 1-200:

The three numbers are:
45 720 -3
720 is invalid
-3 is invalid
this group is invalid.

If you need more explanation from me please email me. Id like to get this one shown to me so I can do the rest of them on my own.

2007-08-05 07:17:17 · 2 answers · asked by Anonymous in Computers & Internet Programming & Design

2 answers

#include

void main()
{
int largest,smallest,range;

cout << "\nEnter 3 numbers\n";
cin >> largest >> smallest >> range;

//check if these numbers > 0 and <=200
if(largest < smallest)
{ //swap numbers
largest = largest + smallest;
smallest = largest - smallest;
largest = largest - smallest;
}
if(largest < range)
{ //swap numbers
largest = largest + range;
range = largest - range;
largest = largest - range;
}
if(range < smallest)
{ //swap numbers
smallest = smallest + range;
range = smallest - range;
smallest = smallest - range;
}
range = largest - smallest;
cout << "\nLargest is " << largest;
cout << "\nSmallest is " << smallest;
cout << "\nRange is " << range;
}

2007-08-08 22:44:45 · answer #1 · answered by E.M.Bed 5 · 0 0

if you're only given 3 numbers, just assign the first one to a variable and treat it as the smallest...read the next number and treat it as the largest if it is larger than the smallest, otherwise flip the values in the variables and finally read in the last value and compare. Then calculate the range.

2007-08-05 14:22:53 · answer #2 · answered by mdigitale 7 · 0 0

fedest.com, questions and answers