Hello, I'm new here and I could use some help please.
Im trying to learn c++ with a book called Programming Principles and Practice Using C++.
Im on Chapter 3 now, and so far not having to many problems. But i am stuck on one of the exercises at the end of the chapter.
I did do a search for this and found one result, but they way they coded it was different than mine.
The exercise is below:
Write a program that prompts the user to enter three integer values, and
then outputs the values in numerical sequence separated by commas. So,
if the user enters the values 10 4 6, the output should be 4, 6, 10. If twO
values arc the same, they should just be ordered together. So, the input 4
54 should give 4, 4, 5.
Now, i thought this would be simple, but I am having some issues with it. Some of it works and some of it doesnt.
I'm sure there are better ways of getting this to work, but as far as I know, im only supposed to use IF's.
My problem is, IF statements 1, 2 and 6 work just fine, but the 3 in the middle dont. I dont really understand why.
When I run it and i try to use 3, which i labeled BAC it works fine if the 4th IF isnt in there,but with it, it outputs both BAC and BCA. 5 does nothing at all.
Hopefully I dont confuse anyone the way i explained it. Been trying to do this for the last 3-4 hours and my brain is fried.
int main()
{
int a=0;
int b=0;
int c=0;
cout<<"Please type in 3 numbers.\n";
cout<<"A: "; cin>>a; cout<<"\n";
cout<<"B: "; cin>>b; cout<<"\n";
cout<<"C: "; cin>>c; cout<<"\n";
cout<<"You typed in "<<a<<" "<<b<<" "<<c<<" .\n\n";
// ABC
// 123
if (a<b && a<c && b<c) // ABC, 123
cout<<"A is less than B, and C, but B is less than C. ABC.\n\n";
if (a<c && a<b && c<b) // ACB, 132
cout<<"A is less than B, and C, but C is less than B. ACB.\n\n";
if (b<a && b<c && a<c) // BAC 213
cout<<"B is less than A, and C, but A is less than C. BAC. \n\n";
if (b<a && b<c && c>a) // BCA 231
cout<<"B is less than A, and C, but C is less than A. BCA. \n\n";
if (c<a && c<b && a<b) //cab 312
cout<<"woot.\n";
if (c<a && c<b && b<a) //cba 321
cout<<"blah.\n";
keep_window_open();
}