C++ :: Store Random Numbers And Sort Function

Oct 7, 2014

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <algorithm>
using namespace std;

const int s = 12, p = 6;
int x[s][p];

[Code] ....

Names: P1 P2 P3 P4 P5 P6 AVER.

EVIKE 41 85 72 38 80 69 64.17
KKASV 65 68 96 22 49 67 71.86
YCXFX 51 61 63 87 66 24 70.64
FADPO 80 83 71 60 64 52 80.11
OEJUV 90 60 49 31 23 99 72.02
POEYL 94 11 25 24 51 15 48.67
VRVIP 13 39 67 97 19 76 59.94
QNQRQ 12 33 99 18 92 35 58.16
OOVAO 74 0 95 71 39 33 61.69
NCBXC 39 32 37 45 57 71 57.12
ATXDK 95 5 71 24 86 8 57.69
IXJSW 51 54 74 24 75 70 67.61
AVER. 58.75 49.15 72.35 51.11 62.68 56.81

1: Sort Alphabetically
2: Sort Grades Increasing Order (Student)
3: Sort Grades Increasing Order (Project)
4: End Program Enter choice: 2

Names: P1 P2 P3 P4 P5 P6 AVER.

XXZRZ 41 72 38 80 69 65 60.83
OKETL 68 85 22 49 67 51 67.14
GZQRC 61 63 87 66 24 80 74.69
OJWAY 83 71 60 64 52 90 82.45
PSAJL 60 49 31 23 96 94 72.57
AOVLZ 11 25 24 51 15 13 35.26
CPWSR 39 67 97 19 76 12 57.54
IZCOB 33 99 18 92 35 74 68.09
IJTVD 0 95 71 39 33 39 57.52
LDVGY 32 37 45 57 71 95 65.75
MBORX 5 71 24 86 8 51 51.79
XOHGM 54 74 24 75 70 0 58.13
AVER. 40.58 70.72 50.98 62.66 56.56 60.05

1: Sort Alphabetically
2: Sort Grades Increasing Order (Student)
3: Sort Grades Increasing Order (Project)
4: End Program Enter choice:

Why my sort is not working. Also, I want to keep the same random numbers for the continuation of the program, I don't want new randomized values when I display the table.

View 4 Replies


ADVERTISEMENT

C :: Store Random Numbers In Array

Jan 11, 2015

i cannot print the values stored in the array ?

Code:
#include<stdio.h>
#include<math.h>
#include<time.h>
#include<stdlib.h>
double randf();

[Code] ....

View 7 Replies View Related

C :: Bubble Sort With Random Numbers

Nov 6, 2014

i'm trying to fill an array with random numbers and then sort them via bubblesort. it seems to work so far. the problem is, that i seem to get the same numbers for the same input. somehow the randomness isn't working.

Code:

#include <stdio.h>
#include <stdlib.h>
int main() {
int a, b, c, d, e, f;
}

[code]....

View 3 Replies View Related

C :: How To Store All Random Generated Numbers In Array

Feb 27, 2013

So we're having an assignment for school where you code a Roulette game which simulates you playing and you can choose how many times you "play" to check how many times you'd win (if that makes any sense, im german :P)

Anyways, the problem is how do i store all the random generated numbers in an array while NOT doing this (it's just a snip):

Code:

void randomzahl(void){
int i;
int zahl5[5];
int zahl10[10];
int zahl100[100];
int zahl1000[1000];
int zahl10000[10000];
if(runden == 5)

[Code]...

View 3 Replies View Related

C++ :: Sort Ascending Random Numbers - Vectors

Oct 21, 2013

I'm trying to sort random numbers in ascending order and I was wondering how I should go about that.

Here's what I currently have.

#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;

[Code].....

I'm trying to put our algorithm between the ////'s. We're only allowed to use for loops also. What I currently have is the minimum number finder and the use of temp to find the values. However, it doesn't seem to be working.

View 2 Replies View Related

C# :: Sort Array Of Random Numbers By Passing It To Method

Jun 28, 2012

I am trying to sort an array of random numbers by passing it to a method Sort(), sort the array, and then pass the entire array back to the calling program. Each time I run this though, the array doesn't seem to sort. I'm not sure if the problem lies with my sorting algorithm or if it has something to do with calling the function.

Code:

static void HighAverage(int[] a) {
for (int i = 0; i < a.Length; i++) {
if ((i + 1) % 10 == 0 && i != 0)

[Code].....

View 5 Replies View Related

C++ :: How To Generate 3 Random Numbers Between 1 And 6 Using Function

Apr 30, 2013

I am trying to generate 3 random numbers between 1 and 6 using a function called generate_rand. but everytime im having an error : no oprators "<<" matches these operands and the last error was :end of file found before the left brace

my program is the following :

# include<iostream>
#include<cstdlib>
using namespace std;

[Code]....

View 6 Replies View Related

C++ :: Timer Function - Generating Seed For Random Numbers

Nov 14, 2014

for (int i=0; i<15; i++)
{
nx[i]=rand()%8+1;
printf("%d",nx[i]);
}

I want to the function of timer "srand(time(NULL))" to generate seed for random numbers. By running this for loop,I think I should expect random numbers ranging from 1 to 8.However, I get some wried numbers from the console window like 88,044,077,066,088,088,066,022,044,044,088,022,033,66814990522,-156026525933,1606416712. One more thing,I think I am going to have 15 outputs, but why I get 16 instead every time.

View 1 Replies View Related

C++ :: Make 10 Random Numbers Thus Making 10 Random Flips Of Coin?

Aug 31, 2013

I want to make 10 random numbers thus making 10 random flips of a coin. I am getting 10 tails or 10 heads!

Code: #include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main(int argc, const char * argv[])
{

[Code].....

View 4 Replies View Related

C++ :: Find Prime Numbers Between Given Pair Of Numbers And Store Them Into Array?

Apr 18, 2014

Find all the prime numbers between a given pair of numbers. Numbers should be read in from an input file called "numbers.txt" and find all the prime numbers between them. Store the prime numbers in an array, then sort the array from greatest to least. Display the array before and after the sort.

I'm stuck on how to put the prime numbers into an array.

The input file has the numbers 1 & 100.

Here's what I have so far.

#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream fin;
fin.open("numbers.txt");

[Code] .....

View 1 Replies View Related

C :: Radix Sort Function To Sort Array Of 64 Bit Unsigned Integers

Aug 19, 2013

Example radix sort function to sort an array of 64 bit unsigned integers. To allow for variable bin sizes, the array is scanned one time to create a matrix of 8 histograms of 256 counts each, corresponding to the number of instances of each possible 8 bit value in the 8 bytes of each integer, and the histograms are then converted into indices by summing the histograms counts. Then a radix sort is performed using the matrix of indices, post incrementing each index as it is used.

Code:
typedef unsigned long long UI64;
typedef unsigned long long *PUI64;
PUI64 RadixSort(PUI64 pData, PUI64 pTemp, size_t count) {
size_t mIndex[8][256] = {0};
/* index matrix */
PUI64 pDst, pSrc, pTmp;
size_t i,j,m,n;
UI64 u;

[Code]....

View 9 Replies View Related

C++ :: How To Generate And Then Store Random Number

Nov 6, 2014

So I have to generate a random number between 1 and 6 and then store that same random number into an int variable. Eg, if the random number is 4, that must be stored into int i.

View 7 Replies View Related

C++ :: Generate Random Integers In The Range And Store Them In A Vector

Sep 3, 2014

You are to write a C++ program to generate random integers in the range [ LOW = 1, HIGH = 10000 ] and to store them in a vector < int > of size VEC_SIZE = 250. Then, sort the contents of the vector (in ascending order) and display it on stdout.

To sort the contents of a vector, use the sort ( ) function from the STL. In addition to the main ( ) routine, implement the following subroutines in your program:

• void genRndNums ( vector < int >& v ) : This routine generates VEC_SIZE integers and puts them in vector v. Initializes the random number generator (RNG) by calling the function srand ( ) with the seed value SEED = 1, and generates random integers by calling the function rand ( ).

• void printVec ( const vector < int >& v ) : This routine displays the contents of vector v on stdout, printing exactly NO_ITEMS = 12 numbers on a single line, except perhaps the last line. The sorted numbers need to be properly aligned on the output. For each printed number, allocate ITEM_W = 5 spaces on stdout.

Programming Notes:

• You are not allowed to use any I/O functions from the C library, such as scanf or printf. Instead, use the I/O functions from the C++ library, such as cin or cout.
• Let v be a vector of integers, then the call: sort ( v.begin ( ), v.end ( ) ) sorts the elements of v in ascending order. The detailed description of the sort ( ) routine can be found on the course web site and in the course textbook.
• Execute the srand ( ) function only once before generating the first random integer with the given seed value SEED. The rand ( ) function generates a random integer in the range [ 0, RAND_MAX ], where the constant value RAND_MAX is the largest random integer returned by the rand ( ) function and its value is system dependent. To normalize the return value to a value in the range [ LOW, HIGH ], execute: rand ( ) % ( HIGH – LOW + 1 ) + LOW.

View 1 Replies View Related

C++ :: Unable To Create Random Array Of 100 Int Between 0 And 250 To Sort Them And Print

Nov 25, 2013

I seem to get an error after int main (void) saying 'a function definition isnt aloowed here before { token? And then also at the end of main saying 'expexted } at end of output?

My programme is trying to create a random array of 100 ints between 0 and 250, sort them and print them.

Here is my code:

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <cstring>
void bubbleSort(int *array,int length)//Bubble sort function {
int i,j;
for(i=0;i<10;i++)

[Code]....

View 4 Replies View Related

C++ :: Merge Sort Algorithm - Output Random Results

Sep 16, 2012

I am trying to code a merge sort algoritm, using my knowledge of C++. I have made some code but it is not working. It is giving some random results.

Code:

#include <cstdlib>
#include <iostream>
using namespace std;
void print(int *niz) {

[Code] ....

View 1 Replies View Related

C++ :: How To Sort A 1D Array Using Function Sort

Mar 22, 2013

how to sort a 1D array using function sort().but if i have a 2D array how do i sort only 1 row of it (or column)?

View 2 Replies View Related

C++ :: How To Store Names And Numbers In Array

Jul 25, 2014

Can names and numbers be stored in one array ? Like a telephone directory?

View 1 Replies View Related

C/C++ :: Program Which Ask For X Numbers And Store Them In Array

Nov 22, 2014

This is in c. Write a program which asks for X numbers, and stores them in an array.

The program then asks the user to enter a number to look for, and tells the user how many times that number appears in the array of numbers (if any), and the array index which contain the number

Make an array of the indexes where the number was found, and then format your output to match my output.

Sample Run:

How many numbers would you like to enter: 5

Please enter a number:1
Please enter a number:2
Please enter a number:3
Please enter a number:4
Please enter a number:2

The numbers you enter were: 1, 2, 3, 4, 2
Please enter a number to find: 2
The number appears 2 times, at array ellements with indexes 1, 4

Press any key to continue . . .

View 10 Replies View Related

C :: Sort Numbers In Order In Programming

Feb 19, 2014

Write a program that orders three double numbers by increasing value. The program should include a function named sort3 that takes three double * arguments (pointer to double). The function prototype is void sort3(double *x, double *y, double *z); The function should reorder the values pointed to by its arguments so that after the call sort3(&x, &y, &z); the numbers satisfy . Your program should input data and print results using the following format:

Enter three numbers: 4.7 1.4 3.2
The ordered sequence is: 1.4 3.2 4.7

And here is my program: C code - 32 lines - codepad

I am getting a lot of errors when I run it through GCC. I can only use pointers.

View 4 Replies View Related

C/C++ :: Sort Out Input - Getting Rid Of Chars And Only Using Numbers

Apr 2, 2014

I was supposed to sort out an input, getting rid of chars and only using the numbers. So 5a6g7we87hj9 would become 567879. I might be wrong in some way, but I used

if (scanf("%d", &n) {
printf(" %d", n);
}
else {
printf("Error);
}

and it sorted correctly.

View 1 Replies View Related

C :: Code That Will Store PID Numbers Of Child After A Fork?

Aug 8, 2013

I am currently trying to write a code that will store PID numbers of a child after a fork, I have to be able to enter an amount that will be created, so far I have managed to be able to get them to print (which puts me on the right path as far as I am concerned) but I am having issues. Using the following code:

Code:

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>

[Code].....

View 3 Replies View Related

C++ :: Program To Store 10 Decimal Numbers In Array

Sep 24, 2014

Write a program which stores 10 decimal numbers in an array. For these numbers accept input from the users. Once the array is populated do the following:

Display each elements of the array
Display the sum of all the elements of array

View 1 Replies View Related

C++ :: Numbers Game - Store Current Low Number

Dec 14, 2013

I have a program that stores current a low numbers. The Object is to Store the low number every time time one is presented. so say I start the function the first number is the low number. but the trouble im having it once the function is called again it starts over(low number). Is there a way I can keep the function value once the function is called again? Any better way of doing this while keeping function in a class?

double a;
class rff{
public:
void FGH() {
doubleb=0;
cout<< "pick a number"<<endl;

[Code] ....

View 1 Replies View Related

C/C++ :: Using Linked List To Store Guessed Numbers

Apr 26, 2015

Rewriting a program to convert an array based list to a linked list. The program has a user guess a number [1-100] until the correct answer is guessed. I only want to give hints if a duplicate isn't guessed.

while (aGuess-> != p->guess) doesn't work and I haven't been able to troubleshoot myself.

while (aGuess->guess != p->guess) {
if ( aGuess->guess > a ) {
cout << "That's too high -- try again: ";
} // if guess > a

[Code] ....

View 1 Replies View Related

C :: Program To Sort Numbers From Highest To Lowest

Apr 7, 2013

I cannot get this program from having a continuous loop. I need to have a user-defined loop.

Here is what I have so far:

Code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int a,b,c,high,med,low;

[Code] ....

View 7 Replies View Related

C :: Sort Numbers From Highest To Lowest Using Qsort?

Sep 28, 2014

How do i sort numbers from highest to lowest using qsort? I dont have a code. I dont know how to use this one.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved