//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!!?
You haven't defined blocks for block operation. For example, your for statement is not followed by a curly brace, so only the next statement is part of the for loop. There is no curly brace following the if statement, so only the printf is included in the condition, the scanf is not, and then the else statement is nonsensical.
I'm not exactly sure what you intended to do with this code, so I'll just give you an example. Note that the dot spaces (' . . ') are just to provide appropriate indentation.
for (a = 0; a %26lt; 10; a++) {
. . operand[a] = rand() % 10 + 1;
. . operand[a + 1] = rand() % 10 + 1;
}
This example will perform both assignments into operand for every value of a from 0 through 9.
brenda song
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment