60 373
Assignments Done
98,1%
Successfully Done
In April 2018

Answer to Question #7328 in C++ for Aaron Slone

Question #7328
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
Expert's answer
#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!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions