I'm in the process of writing a program. I've written most of it, but there are a few things that I can't seem to fix. Firstly, after the user inputs "h" or "t," the output gets displayed twice. Also, it seems as though, even if the computerpointcounter reaches 25, it will not display the message: "Computer won!." Can anyone help me with these? Thanks.
Code:
#include <stdio.h>
#include <time.h>
#include <stdio.h>
int main () {
int userpointcounter=0, computerpointcounter=0,random=0;
char userpick;
printf("Welcome to MindReader.\n\n");
while(userpointcounter<25 || computerpointcounter<25)
{
printf("Guess heads or tails and I'll predict your guess.\nWhat is your guess [h/t] ?");
scanf("%c",&userpick);
int computerpick = srand( (unsigned)time( NULL ) %2);
if (computerpick == 1)
{
random='t';
}
if (computerpick == 0)
{
random='h';
}
if(userpick==random)
{
printf("Yes! I too predicted heads.\n");
userpointcounter++;
}
if(userpick!= random)
{
printf("No. I gussed the opposite.\n");
computerpointcounter++;
}
}
if(userpointcounter==25)
{
printf("Congratulations! You won!\n");
}
if(computerpointcounter==25)
printf("Computer won!\n");
}