C/using rand
Expert: Narendra - 3/7/2004
Questioni am suppose to write a c progam that should multiply 2 one digit number using rand it should ask the user multiplication 10 times
then display each time if the answer the user enter is correct or incorrect using rand so if its incorrect u can display out of 4 response eg bad,very bad not that bad ,real bad and it should also display an average of correct answer i have written this so far but i dont know what to do next.
#include<stdio.h>
#include<stdlib.h>
void main ()
{
int ans[];
int i,correct;
for(i=1;i<11;i++){
printf("How much is %d times %d ?",1+rand()%9,1+rand()%9);
scanf("%d",&ans[]);
correct=(1+rand()%9*1+rand()%9);
avg=
if(ans==correct){
printf("good\n");
}
else
printf("bad\n");
}
}
AnswerFirst of all, you have to store the random number in a variable. And remember that, each time you call the rand() function, a new number is returned. Also, you have to use srand() function to initialize the randomizing algorithm.
My sincere suggestion to you is, write an algorithm in plain english (splitting into steps) for what you intend to do, before starting to code. Then only you can code easily.
ssnkumar