G
gc
Hi
I'm working on a rock, scissors, paper program. I think I have most of
it, but I am having trouble with my main function, here is my code:
#include <stdio.h>
#include <stdlib.h> /* for rand() and srand() */
#include <time.h> /* for time() */
/*User Inputs R,P,S,Q*/
int getValidInteger(int min, int max, char prompt[])
{
char userInput;
printf("\nEnter R(ock), P(aper),or S(cissors) or Q(uit): ");
scanf("%c",&userInput);
//userInput=toupper(userInput);
switch(userInput){
case 'Q':return 0;
case 'R':return 1;
case 'P':return 2;
case 'S':return 3;
default: printf("Invalid Choice!%s\n");
}
}
/*Computer Cal it's choice*/
int getCompChoice()
{
int comp = rand()%3;
switch (comp){
case 0: return 'R';
case 1: return 'P';
case 2: return 'S';
}
return comp;
}
void result(int user, int comp)
{
if (user=comp)
printf("Draw\n");
switch (user) {
case 1:
if (comp == 'R')
printf("You Win\n");
case 2:
if (comp == 'P')
printf("You Win\n");
case 3:
if (comp == 'S')
printf("You Win\n");
default:
printf("You Loose\n");
exit(1);
}
return;
}
main(void)
{
int score = 0;
srand(time(NULL));/* seed the random number generator*/
int getValidInteger();
if (getValidInteger=getCompChoice) score++;
return score;
}
I think I am going about it the wrong way. Could someone steer my in
the right direction, without giving me the answer.
GC
I'm working on a rock, scissors, paper program. I think I have most of
it, but I am having trouble with my main function, here is my code:
#include <stdio.h>
#include <stdlib.h> /* for rand() and srand() */
#include <time.h> /* for time() */
/*User Inputs R,P,S,Q*/
int getValidInteger(int min, int max, char prompt[])
{
char userInput;
printf("\nEnter R(ock), P(aper),or S(cissors) or Q(uit): ");
scanf("%c",&userInput);
//userInput=toupper(userInput);
switch(userInput){
case 'Q':return 0;
case 'R':return 1;
case 'P':return 2;
case 'S':return 3;
default: printf("Invalid Choice!%s\n");
}
}
/*Computer Cal it's choice*/
int getCompChoice()
{
int comp = rand()%3;
switch (comp){
case 0: return 'R';
case 1: return 'P';
case 2: return 'S';
}
return comp;
}
void result(int user, int comp)
{
if (user=comp)
printf("Draw\n");
switch (user) {
case 1:
if (comp == 'R')
printf("You Win\n");
case 2:
if (comp == 'P')
printf("You Win\n");
case 3:
if (comp == 'S')
printf("You Win\n");
default:
printf("You Loose\n");
exit(1);
}
return;
}
main(void)
{
int score = 0;
srand(time(NULL));/* seed the random number generator*/
int getValidInteger();
if (getValidInteger=getCompChoice) score++;
return score;
}
I think I am going about it the wrong way. Could someone steer my in
the right direction, without giving me the answer.
GC