Saturday, May 9, 2009

C math quiz program Help?

Hello, I'm learning to Program in C and I have to create a math quiz. The user is supposed to enter the amount of questions they want to answer. I'm trying to get a Random number generator to produce two random numbers and then a random sign (+ - * /) so basically it looks like this (Ex. 4+4 = ) Then the user inputs the answer and it goes on to the next question till the person answered all of them. Then I wanted a text file that containted all the questions and answers..





Here is what I have so far... which is reall slim..any ideas??





#include%26lt;stdio.h%26gt;


#include%26lt;stdlib.h%26gt;


#include%26lt;time.h%26gt;


#include%26lt;string.h%26gt;





int randomNumbers(){





rand() % 100 + 1;


}


int num(){


randomNumbers();


}


char sign(){


}


int equation(int a, int b, char c){


}


int randomSign(){


int sign = 1 + rand() % 5;


if (sign == 1)


return '+';


if (sign == 2)


return '-';


if (sign == 3)


return '*';


if (sign == 4)


return '/';


if (sign == 5)


return '%';


}





int main(){











int correct = 0;


int x, y, answer, correctanswer;


char z;





x = num();


y = num();


z = sign();





printf(" %d %s %d =", x,y,z);





return 0;


}

C math quiz program Help?
Hmm... I see a couple of problems right off the bat.





1. Your randomNumbers() function is not returning anything. You need to return the value (i.e. return rand() % 100 + 1;)





2. There is no need for the num() function.





3. You can also use "case" statements instead of the multiple if statements in randomSign()





4. You call a function called equation() from within the sign() function, but I don't see an equation() function defined anywhere.





5. Maybe you should do this to assign values


x = randomNumbers()


y = randomNumbers()


z = randomSign()





and get rid of num() and sign().





Just some suggestions.... Good Luck! :)


No comments:

Post a Comment