### Program9

Hello,

I decided to write a program as follows:

Write a program that prompts the user to enter three integer values, and then outputs the values in numerical secuence separated by commas. So, if the user enters the values 10 4 6, the output should be 4,6,10. If two values are the same, they should just be ordered together. So, the input 4 5 4 should give 4,4,5.

Now I have know idea how to do this smartly (just few lines of code) but I have experimented sorting each case separately. Is there an operator for and? I have used the & operator which means or.

 ``123456789101112131415161718192021222324252627282930313233343536`` ``````#include #include #include #include using namespace std; int main() { int a=0; int b=0; int c=0; cout<<"Enter three integer values:\n"; cin>>a>>b>>c; if (a
Last edited on
 I have used the & operator which means or.
You have use && operator which means and. Like "left hand condition and right hand condition must be true for expression to be true".
There is logical or operator: `||` (or `or` if you wish)
Yep, that might be true but I haven`t touched the code at all. I don`t think I need the or-statement at all if I can cover all the possibilities with and-statements.

Now however my program acts as follows:

Enter three integer values:
10 4 6

Followed by empty space!
10 4 6 doesn't fit any of the conditions you've defined so far.

With three numbers, it's not that bad to figure out all the possible sequences they could be in, but with a larger set of numbers, I'd want to use some sort of sorting algorithm.

If you were going to sort the numbers into low to high order, they could be in order different ways.

abc, acb, bac, bca, cab, cba

OT - but when you include a file at the top of the program, you're essentially cutting and pasting the contents of that file into your program, so if you include files you don't need, you're making your program bigger than it has to be.
Hi @pacman here is 2
of the 6 possible combinations;
(as @wildblue said) complete the rest

To sort numbers, it's a better idea to use
containers (arrays,vectors) + sort algorithms;

 ``123456789101112131415161718192021222324252627`` ``````//SortValues.cpp //## #include using namespace std; int main(){ int a,b,c; cout<<"Enter three integer values:\n"; cin>>a>>b>>c; if(ac)cout<

EDIT: I am not considering repeated numbers
Last edited on
Topic archived. No new replies allowed.