//WHATS WRONG WITH MY CODE?
#include
#include
#include
#include
#include
int main ()
{
int operand[19];
int ans;
int a,b;
int operation;
/* initialize random seed: */
srand ( time(NULL) );
for(a = 0;a<10;a++)
{
operand[a] = rand() % 10 + 1;
operand[a+1]= rand() % 10 + 1;
b = rand() % 1 + 1;
if(b == 0) //THE OPERATION IS SUBTRACTION
{
printf("%d - %d = ",operand[a],operand[a+1]);
scanf(" %d ", &ans);
else //ELSE THE OPERATION IS ADDITION
printf(" %d + %d= ",operand[a],operand[a+1]);
scanf(" %d ", &ans);
}
}
getch();
return 0;
}
/* I WANT TO CREATE A PROGRAM THAT RANDOMIZE A NUMBER AND ALSO IF THE VARIABLE B WILL DECLARE 0 THE OPERATION IS SUBTRACTION BUT IF 1 THE OPERATION IS ADDITION, I THINK MY LOGIC IS RIGHT BUT THE PROGRAM ALWAYS SAY THAT THERE IS A SYNTAX ERROR BEFORE "ELSE" */
2007-12-20
22:33:50
·
4 answers
·
asked by
AngryProgrammer
1
in
Computers & Internet
➔ Programming & Design