Monday, May 24, 2010

Problems on C program!!?

//what error is on my program?


//SIMPLE MATH QUIZ


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


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


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


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


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


int main ()


{


int operand[19];


int ans;


int a;


int operation;


/* initialize random seed: */





srand ( time(NULL) );


for(a = 0;a%26lt;10;a++)


operand[a] = rand() % 10 + 1;


operand[a+1]= rand() % 10 + 1;


a = rand() % 1 + 1;


if(a == 0) //if 0, the arithmetic must be subtraction


printf("%d - %d = ",operand[a],operand[a+1]);


scanf(" %d ", %26amp;ans);


else //else it is addition


printf(" %d + %d= ",operand[a],operand[a+1]);


scanf(" %d ", %26amp;ans);





getch();


return 0;


}


//kindly edit my code...and explain what's wrong with this? tnx!

Problems on C program!!?
for(a = 0; a %26lt; 10; a++)


{ /*You should ALWAYS use an opening and closing braces for iterations*/}





if(a == 0)


{ /*You should ALWAYS use an opening and closing braces if and only if two or more statements are placed in an if statement but it is optional to use the braces if there is only one statement in an if statement...*/}





*There is no need for you to initialize random seed!
Reply:if... else... block without opening and closing brace.


No comments:

Post a Comment