Okay, let's try this again. Guys I really need help with this assignment..
k
wat is it?
Problem 2
#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...
It has to sort 4 numbers, it can only sort 3 for now..
who gave this good answer? That's not good answer
*that's not a good answer..
you have not written anything for condition 'else if(c<d)'. complete that condition.
I know i haven't that's because I can't..
I would use an array to hold the data, and then a double loop (it's order N^2 ) to do a simple sort.
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..
Again IF/ELSE statements ONLY
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
Hey Bahrom
First Compare three Numbers ...then compare the fourth one with all of the three which are arranged ...
Join our real-time social learning platform and learn together with your friends!