I know that im not supposed to write like this but i just want to know how to sort 4 random chosen numbers (chosen by pc) in ascending order. Just the basic insert. Imstill abeginnerand cant use arrays!

3
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by WaltP

If you know not to, why are you?

You don't know how to use arrays, or you aren't allowed to use arrays? There is a big difference, and the answer drastically changes the required algorithm(s). Someone might help you if you answer that, and take some time to think about your algorithm.

Edited by Fbody: n/a

Im not allowed to use arrays. Sorry bout that!

This is my algorithm and what ive got so far!!

``````#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;
int DICE_ROLL();
int ARRANGE()
int main(
int argc, char* argv)
{
int numRolls;
int arrRolls[6];
int dieRoll;

srand((unsigned)time(0));

cout << "How many times would you like to roll the dice?" <<          endl;
cin >> numRolls;

for (int k = 0; k < 6; k++)
{
arrRolls[k] = 0;
}

for (int i = 1; i <= numRolls; i++)
{
dieRoll = DICE_ROLL();
cout << "Die Roll " << i << ": " << dieRoll << endl;
arrRolls[dieRoll - 1]++;
}

while (

for (int j = 0; j < 6; j++)
{
cout << "The number " << j + 1 << " was rolled " <<      arrRolls[j] << " times." << endl;
}
}

int DICE_ROLL()
{
int result;

result = (rand() % 6) + 1;

return result;
}``````

Edited by WaltP: Added CODE tags -- with all the help about them, how could you miss using them????

I assume your question is still sorting? I don't see any attempt so it's hard to know what you're having trouble with.