Displaying values in reverse order and from smallest to largest (HELP!!)

Hey guys, so I'm starting to learn C++ at Uni and I'm doing one of these questions in tutorial to help you grasp what you learnt in a lecture hall and I've hit a bit of a snag with this question, what I have basically been asked to do is make a little program that asks the user to enter three values for "a, b and c" then display the values in reverse order but then further display the order from smallest to largest..

I've only just started and as you can see from my code, I know very little but I've done some research online about displaying values that have been inputted to smallest to largest and the code people present and get answers with goes way over my head as I've had roughly 2hrs worth of experience.

so basically what I'm asking is, can someone put up a code (basic one so I understand it) and then maybe give me some hints on how the code works and why so I can study it and understand it. and then allow myself to do it myself

Thanks in advance...

btw, the "if" code is there from my last question but i'm not sure if it will help in this question so I've kept it there just in case

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 #include <iostream>
#include <Windows.h>

using namespace std;

int main(void) 
{
	

	int a = 0, b = 0, c = 0, hold = 0;  // three letters and a hold that will be assigned a number by the user

    cout << "Please enter a value for a" << endl; // entering the values for a
	cin >> a;

	cout << "Please enter a value for b" << endl; // entering the values for b
	cin >> b;

	cout << "Please enter a value for c" << endl; // entering the values for c
	cin >> c;

	if (a >= b < c) // The command to test if number one is bigger than number two and the response regarding the outcome of the comparsion 
	{
		cout << "Smallest value to largest value is now is accending order" << endl;
		hold = a;
		a = b;
		b = hold;
		c = c;

		cout << "a is now:" << a << endl;
		cout << "b is now:" << b << endl;
		cout << "c is now:" << c << endl;

	}
	else
	{
		cout << "a holds a bigger value than c";
	}

	cout << "\n\n\n";
	system("pause");
}
closed account (1CfG1hU5)
here's a sort function

1
2
3
4
5
6
7
8
9
10
11
12
13
void bubble(int array[], int size)
 {
   int temp, t, r;

   for (t = 0; t < size; t++) 
    for (r = 0; r < size; r++)
      if (array[t] < array[r])  // switch to '>' and descends
        {
          temp = array[t];
          array[t] = array[r];
          array[r] = temp;
        }
  }

Last edited on
ok thanks, but could you explain what half of this information means, the only things I've really been taught is what is in my code, so bubble and array and stuff like that goes over my head even tho I've tried to read and understand what it basically means the code just doesn't scream out what its saying to me, you know?
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>

int main() // main(void) was my earlier mistake 
{
	int a = 0, b = 0, c = 0, hold = 0;  // three letters and a hold that will be assigned a number by the user

    std::cout << "Please enter a value for a" << std::endl; // entering the values for a
	cin >> a;

	std::cout << "Please enter a value for b" << std::endl; // entering the values for b
	std::cin >> b;

	std::cout << "Please enter a value for c" << std::endl; // entering the values for c
	std::cin >> c;

	if (a>b)
	{
	    hold = a;
	  a = b;
	  b = hold;
	}
	
	if (b>c)
	{
	   // need some lines here
	}
	
	if (// need another condition here)
	{
	   // need some lines here
	}
	
    std::cout << a << '\t' << b << '\t' << c << '\n';
    // need another line here
    
    return 0;
}
Last edited on
closed account (1CfG1hU5)
since you're using <iostream>

put:

 
using namespace std;


before main func
Last edited on
@jt1

That is not a good idea, kemort has done the right thing, & the OP should remove theirs, and do the same as kemort.

Google as to why that is so, there is plenty written about it.

To be super picky, the use of void for functions with no parameters has never been a requirement for C++, but is a matter of preference.

Cheers
closed account (1CfG1hU5)
int a, b, c, are all decimal numbers, not converted to letters yet, but
could be used to output a letter with the right code, %c for example.

there are declarations, and inputting from keyboard with cin.
work on the code some more to can be executed at cpp.sh with button on screen

for this line

 
std::cout << a << '\t' << b << '\t' << c << '\n';


with cout, can also use " " between "<<" and "<<" for spacing

there's an example somehwere here about finding the lowest and highest numbers
of integers. try to find.

responding to 2nd pasted example

here's some pages

did not look over these web pages

http://www.cplusplus.com/forum/beginner/83374/
http://www.cplusplus.com/forum/beginner/38799/

this one may be promising

http://www.cplusplus.com/forum/beginner/108341/



Last edited on
Thanks kemort, I understood your much better and made more sense nad you've given me some work to do myself, greatly appreciated
closed account (48T7M4Gy)
My pleasure Collwyr. There are lots of ways to skin a cat as you can see but with just 3 numbers you can afford to plod your way through it and learn something. I'll be interested to see what you get in place of my line 34 comment. ;)
Last edited on
closed account (48T7M4Gy)
@ The IdeasMan

Thanks for pointing out my void blooper. It was an artifact of the cut and paste process and I didn't notice it. <Blush>
@ Kemort, i'm currently on that line and have been pondering what you meant by it... I look forward to seeing what I can think up of.
@kemort

No worries, it wasn't aimed at you anyway !! :+D As for C&P artefacts - I think we have all done that more than once, and it probably won't be the last time!

Cheers
closed account (48T7M4Gy)
@collwyr

I'll give you a couple of tips:-

1. The extra bits are not complicated - try it with three coins or similar.
2. The second if is a no-brainer.
3. The third if is primarily a cut and paste job.
4. Remember a, b and c can be written in any order after they go throug the 3 if's.
5. There is no magic.
Last edited on
@Kemort

soon as i can figure out why my visual studios has decided to not work properly, i'll get back to you...

and I love magic
Topic archived. No new replies allowed.