Hi guys need a bit of help, i am making a prgram but i am stuck. I am displaying

9 8 7 6 5 4 3 2 1

and i ask the user to put in order,. So like 1 2 3 4 5 ...etc. Now i need it so that if the user presses 8. It goes behind 9 and then preses 7 which goes infron of 8. How cna i do this? I am ew to c++

// String as array
#include <iostream>
#include <vector>
#include <string>
#include <conio.h>
#include <windows.h>
#include <stdio.h> 
#include <cstdlib>
#include <iostream>
#include <ctime> // For time()
#include <cstdlib> // For srand() and rand()


using namespace std;

int main()
{
	int Num;
int x;
srand(time(0));; 
for (x = 0; x < 10 ; x++)
cout<< (rand() % 10) + 1<< " "; //creates random numbers from 1 to 10
cout<<""<<endl;
cout<<" Please enter a Number"<<endl;

return(0);
}

they are random of curse atm. any help woudl be appericiated.

Recommended Answers

All 4 Replies

Does no one read the forum rules ??? At least a glance ??? Please go through this once.Use Code Tags.

And Please Use English here.This is not a mobile chat zone.

Your mistakes :

cout<< (rand() % 10) + 1<< " "; //creates random numbers from 1 to 100

How can you expect the above code to generate random numbers till hundred ? It can generate only until 10.

I really had a hard time understanding what you want and I still am not able to get what you really want to do.

Your statement has something about reorganization and you are using cout.Once you output to the console then how can you even organize it?
Use an array or something to feed in the random generated numbers and also user input numbers and then use some sorting algorithm if your objective is just to arrange the numbers.

Use code tags:

[code=cplusplus] // code goes here

[/code]

or

[code]

// code goes here

[/code]

Your code appears to have gotten cut off. You have some #include statements that you don't need, but that may not be a problem. Don't use conio.h if you can help it.

cout<< (rand() % 10) + 1<< " "; //creates random numbers from 1 to [COLOR="Red"]100[/COLOR]

This creates a random number from 1 to 10, not 1 to 100.

yes sorry guys, my bad i forgot to change the comment. I know it is 1 - 10.

Your program has some problems. I see no attempt to store any values in any variables, so there is nothing to reverse. You create random numbers, but just display them. They aren't stored anywhere. Line 24 has a cout statement requesting an answer, but then the program immediately ends without any cin statement to go along with the question. You're asking a question, then ending the program without waiting for an answer.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.