Ok you guys have been very helpful!
As im sure you can tell i am new to C and also not that experienced in any other language.
I have written another programme that is supposed to count up the frequency of each random number generated!
I am fairly sure there will be a stupid mistake in this code due to the compile errors i recieve from gcc.
Compile errors:
Code:
random2.c: In function arrayswitch:
random2.c:9: error: expected =, ,, ;, asm or __attribute__ before { token
random2.c:37: error: expected =, ,, ;, asm or __attribute__ before { token
random2.c:5: error: old-style parameter declarations in prototyped function definition
random2.c:5: error: parameter name omitted
random2.c:53: error: expected { at end of input
Code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void arrayswitch(int)
int frequency[9];
int main()
{
int randnum ;
float mean;
int x;
srand(time(0));
for (x = 1; x <= 10,000; x++)
{
randnum =( 10.0*rand()/(RAND_MAX + 1.0));
arrayswitch(randnum);
}
printf("Frequency of 0: %d\n", frequency[0]);
printf("Frequency of 1: %d\n", frequency[1]);
printf("Frequency of 2: %d\n", frequency[2]);
printf("Frequency of 3: %d\n", frequency[3]);
printf("Frequency of 4: %d\n", frequency[4]);
printf("Frequency of 5: %d\n", frequency[5]);
printf("Frequency of 6: %d\n", frequency[6]);
printf("Frequency of 7: %d\n", frequency[7]);
printf("Frequency of 8: %d\n", frequency[8]);
printf("Frequency of 9: %d\n", frequency[9]);
return 0;
}
void arrayswitch(int number)
{
switch(number)
{
Case '0' :frequency[0] = frequency[0] + 1; break;
Case '1' :frequency[1] = frequency[1] + 1; break;
Case '2' :frequency[2] = frequency[2] + 1; break;
Case '3' :frequency[3] = frequency[3] + 1; break;
Case '4' :frequency[4] = frequency[4] + 1; break;
Case '5' :frequency[5] = frequency[5] + 1; break;
Case '6' :frequency[6] = frequency[6] + 1; break;
Case '7' :frequency[7] = frequency[7] + 1; break;
Case '8' :frequency[8] = frequency[8] + 1; break;
Case '9' :frequency[9] = frequency[9] + 1; break;
default :printf("ERROR"); break;
}
}