hi guys,
just began learning C a few days ago so i'm a real beginner. and my compiler is Pelles C.
i'm practicing newfound basics by creating a console based guessing number game. (don't laugh)
i've googled for various examples of random numbers in C and have got things like add stdlib.h and time.h, use randomize(); then the rand function etc, i've tried a few different ways, and pelles c compiles it fine, but went building gives errors of the use of randomize and rand etc.
I was just wondering if someone here can give me the quickest and easiest way to generate a random number for my app. it only needs to be between 1 - 10.
also, as a seperate question if I may (since I don't want to spam the forum with total newb topics), below is my current source code so far (it's small). and the players name is limited to 1 character of course, how do I write it so that the char variable can take a name and then display it in other functions such as "stats" and "game"?
any help would be greatly appriciated and I hope i've not violated any forum rules.
#include <stdio.h>
void singleplayer();
int stats(int r, int p, int c);
int game(int r, int p, int c);
char name;
main()
{
int players;
printf("\n\n--- Guess Number Game! ---\n\n");
printf("is this game for 1 or 2 players? : ");
scanf("%d", &players);
if(players==1)
{
singleplayer();
}
if(players==2)
{
}
}
void singleplayer()
{
int rounds=0;
int playerscore=0;
int computerscore=0;
printf("\n\n1 player selected, you will play against the computer.\n\n");
printf("please enter your name : ");
scanf("\n%c", &name);
stats(rounds, playerscore, computerscore);
game(rounds, playerscore, computerscore);
}
int stats(int r, int p, int c)
{
printf("\n\nCURRENT STATS:\n");
printf("Rounds = %d", r);
printf("\n%c = %d points", name, p);
printf("\nComputer = %d points\n\n", c);
}
int game(int r, int p, int c)
{
int playerselect;
int computerguess;
printf("%c, you are the selector. pick a number 1 - 10 : ", name);
scanf("%d", &playerselect);
printf("\n\nyou picked %d", playerselect);
}