Answer to Question #7328 in C++ for Aaron Slone
Problem:
Write a program that prompts the user to input three numbers. The program should then output the numbers in ascending order.
Note:
I am having issue understanding how to fix this program using if/else statement and put the numbers in ascending order
1
2012-03-15T09:45:11-0400
#include <iostream>
using namespace std;
void main() {
int n[3], tmp, j = 0;
bool flag = true;
for(int i = 0; i < 3; i++){
cout << "Enter the number " << i+1 << ": ";
cin >> n[i];
}
while (flag) {
flag = false;
j++;
for (int i = 0; i < 3 - j; i++) {
if (n[i] > n[i + 1]) {
tmp = n[i];
n[i] = n[i + 1];
n[i + 1] = tmp;
flag = true;
}
else
continue;
}
}
for(int i = 0; i < 3; i++)
cout << n[i] << endl;
}
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
C++
Comments
Leave a comment