3 numbers

The three integers can each be different amounts, or two or more of them can be the same amount. But the values will come from a file "data.txt".
Inside the main function definition, declare four integer variables being sure to give them a descriptive name where it is easy for the reader of the code to know what is stored in each. Making one of them called temp is good as temp stands for "temporary variable" and is used when sorting the three integers.
Prompt the user for three integers, as shown in the example execution of the program (above). Read in the integers and store them, respectively, in three other variable names. For an example, I will use valueA, valueB, and valueC. But yours need to be more descriptive.
Implement the following sorting algorithm in sequence. When the algorithm is complete, the three integers will be sorted such that the current contents of valueA, valueB, and valueC will be in ascending order.
if valueA > valueB then swap valueA and valueB.
if valueB > valueC then swap valueB and valueC.
if valueA > valueB then swap valueA and valueB.
When the algorithm above says to swap the contents of two values x and y, do the following steps in this order inside a set of curly braces:
Store x in temp.
Store y in x.
Store temp in y.
You need to use the curly braces so that all three statements are affected by the same if statement.
Print the current values of the three integers starting with valueA, then valueB, and then valueC . Finally, print the value of the middle integer located in valueB. When printing these values, be sure to follow the format shown in the example execution of the program
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
using namespace std;
int main() {

double number1;
double number2;
double number3;
double minimum;
double middle;
double maximum;
  
   cout << "Enter three integers separated by one or more spaces: ";
   cin >> number1 >> number2 >> number3;
   minimum = number1;
  
   if(number2 < minimum) {
      minimum = number2;
   }
  
   if(number3 < minimum) {
      minimum = number3;
   }
  
   maximum = number1;
   if(number2 > maximum) {
      maximum = number2;
   }
  
   if(number3 > maximum) {
      maximum = number3;
   }
  
   middle = (number1 + number2 + number3) - (minimum + maximum);
   cout << "The sorted values are " << minimum << " " << middle << " " << maximum << endl;
   cout << "The middle value is " << middle << endl;
   return 0;
}

This is what I have so far.
it looks pretty good. was there a question?
I note that you have doubles and ask for integers. Why?



Topic archived. No new replies allowed.