Hi!
I am Abdul-Majeed.
I'm a new student to c. I tried writting a game for random multiplication calculation.
This was a similer questions for me in my midterm exams.
I need friends to inprove it for me.
You can also find faults and make corrections to my code
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
void guesgame(void);
int main ()
{
char name[30];
printf("Please enter your name:\n ");
scanf("%s",name);
printf("Hello! %s and welcome to Abdul-Majeed's Multiplication game\n",name);
printf("Rules for the game:\n1. You will get 5 points for every correct answer\n2. You will loss 5 points for every wrong anwer\n"
"3.The game will end if you score up to 100\nIt will also end when you get 3 questions wrong\nWish you good luck!!!\n");
guesgame();
getch ();
return 0;
}
void guesgame(void)
{
int result,answer,x,y;
int i=0,j=0;
while(1)
{
srand(time(NULL));
x = 1+rand()%10;
y = 1+rand()%10;
result = x*y;
printf("%d * %d = ",x,y);
scanf("%d",&answer);
if (answer == result)
{
printf("\nGood you had it ryt! you have 5 points\n");
i +=5;
}
if (answer != result )
{
printf("\noops! it's wrong. you get -5\n");
j -=5;
}
if(i == 100 || j == -15)
{
printf("Sorry you have no more chance\n\n"
"Thank you for playing Abdul-Majeed's game\n\n"
"Your Total points = %d\n",i);
getch ();
}
}
}