Hey imran I finally figured out how to do that program assignment, give me about ten minutes I will post the solution here.
I mean I will post the program and have you guys test it.
gj, I figure my own way but that used a little bit more than mere if else
LOL I am using 24 if-elses haha
11 more left..
My idea was finding min of a,b,c,d and assigning it to a finding min of b,c,d and assigning it to b finding min of c,d and assigning it to c
hmm nice... How woud you do that? I thought of that, but i just brushed it off saying whatever..
Using some nested if statement and a function.No loops, array needed
ohh 7 more left.. arghhh
I am going to be taking assembly language this fall which is supposed to be fun
3 to go!!! lol I am minoring in programming now.. i decided it is sort of fun.. easier than math at least
Mathematical Computer Science related to math since it is problem solving using programming
Okay done. here's the program.
First test passed
1234 1243 1324 1342 1423 1432 2134 2143 2314 2342 2413 2431 3124 3142 3214 3241 3412 3421 4123 4132 4213 4231 4312 4321 Can you test all of these numbers?
Because the conditions are all dependant on the permutations
How does it handle repeat?
what do u mean repeat? I dunno...
1 3 4 1
oh snap it's not doing anything.. i should have done <=
hold on...
Okay fixed the bug, try again.. hold on let me reupload
here
That was quick
I think it is fool proof now
okay wanna see the source code?
yea, sure
lol I don't think you want to.. anyway hold on..
That was soo annoying to write, simple but annoying
I will try to simplify it
oh, changing to =< was your fix?
yea
very nice, long but very easy to follow
yea i googled all combinations of ABCD.. so I just used that
In this case using brute force seems better than using tricks
yea.. oh wait.. i have to reject anything that is not an integer..
ah nevermind, professor's version is worse
when decimal is entered, it goes off
yea but the requirement says only integers
professor's version also fails
you can write that when accepting input
yea let me add that
I don't understand why you didn't do what I said. Or what imran said. Just 6 ifs
what do u mean? lol I just used the brute force method
So did I.
What I said in your last thread, or what imran said here: " My idea was finding min of a,b,c,d and assigning it to a finding min of b,c,d and assigning it to b finding min of c,d and assigning it to c "
But my approach involve moving around value of a,b,c,d which is kind of annoying
only a little, and he probably is doing it anyway
No, he is just outputing a,b,c,d in different order
oh. still our method only has 6 ifs, not 24
power of copy/paste, lol
also if he used a function to swap the values its not too bad. c++ has references so changing the variables is easy
I tried function, but I don't know how global/local variable works in C++
void swap(int &a, int &b) { int tmp; tmp = a; a = b; b = tmp; }
then just: swap(c,d) does the right thing
swap function? never heard of it..
#include <iostream> using namespace std; void swap(int &x,int &y) { int tmp; tmp= y; y= x; x= tmp; } int main() { int a,b,c,d; cout << "Please enter the 1st integer: " << endl; cin >> a; cout << "Please enter the 2nd integer: " << endl; cin >> b; cout << "Please enter the 3rd integer: " << endl; cin >> c; cout << "Please enter the 4th integer: " << endl; cin >> d; if (a>b) swap(a,b); if (a>c) swap(a,c); if (a>d) swap(a,d); if (b>c) swap(b,c); if (b>d) swap(b,d); if (c>d) swap(c,d); cout << "Sorted: " << a << " " << b << " " << c << " " << d << endl; return 0; }
If you haven't got to call by reference, this might be a bit mysterious.
Wow, nice looks soo good!! let me look up what swap does..
Join our real-time social learning platform and learn together with your friends!