Ask your own question, for FREE!
Mathematics 15 Online
OpenStudy (bahrom7893):

Okay, let's try this again. Guys I really need help with this assignment..

OpenStudy (anonymous):

k

OpenStudy (anonymous):

wat is it?

OpenStudy (bahrom7893):

Problem 2

OpenStudy (bahrom7893):

#include<iostream> using namespace std; int main() { int a, b, c, d; cout << "Please enter the first integer: "; cin >> a; cout << "Please enter the second integer: "; cin >> b; cout << "Please enter the third integer: "; cin >> c; cout << "Please enter the fourth integer: "; cin >> d; if (b<a) { int temp; temp = a; a = b; b = temp; } if (c<a) { int temp; temp = c; c = b; b = a; a = temp; } else if (c<b && c>a) { int temp; temp = b; b = c; c = temp; } else if (c<d) cout << a << " " << b << " " << c << " " << d << endl; system("pause"); return 0; } Here is what I did so far, but the program is incomplete...

OpenStudy (bahrom7893):

It has to sort 4 numbers, it can only sort 3 for now..

OpenStudy (bahrom7893):

who gave this good answer? That's not good answer

OpenStudy (bahrom7893):

*that's not a good answer..

OpenStudy (anonymous):

you have not written anything for condition 'else if(c<d)'. complete that condition.

OpenStudy (bahrom7893):

I know i haven't that's because I can't..

OpenStudy (phi):

I would use an array to hold the data, and then a double loop (it's order N^2 ) to do a simple sort.

OpenStudy (bahrom7893):

How many times do I have to say that I am only allowed if/else statements and we didn't use an array yet anyway so I don't know how to use that..

OpenStudy (bahrom7893):

Again IF/ELSE statements ONLY

OpenStudy (phi):

OK, I came in late to this. The idea is to 1) compare a to each variable in turn, b, c , d, and swap values (whichever order you are doing). If it's small to big (for example), a will have the smallest value after this step. 2) now do the same for b, but compare (and swap if needed) to c and d. b is the next smallest after this step. 3) compare c to d and swap as needed

OpenStudy (anonymous):

Hey Bahrom

OpenStudy (anonymous):

First Compare three Numbers ...then compare the fourth one with all of the three which are arranged ...

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!