0

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
7 Years
Discussion Span
Last Post by WaltP
0

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

0

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????

0

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.

Start with a basic pencil & paper solution.
Write down these numbers.
5, 32, 12, 8
Step by step, how do you sort them if they were on a math assignment?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.