
October 14th, 2007, 12:20 PM
|
|
Contributing User
|
|
Join Date: Sep 2007
Location: America
Posts: 53
Time spent in forums: 8 h 59 m 35 sec
Reputation Power: 0
|
|
|
Can't use a char variable in my equation
So, this chunk of program is a part of a bigger program, and what i need it to do, is be able to prompt the user for an operator, scan it into a variable called mod, then reproduce mod in an equation, but it gives me an error when i try to compile it
here is the code, thanks
Code:
#include <stdio.h>
main()
{
char mod;
int x, y, z;
x = 5;
y = 6;
printf("Enter in an operator ---> ");
scanf("%c", &mod);
z = ((x) mod (y)); /* want this equation to
work, I want x to be added, subtrated, whatever 'mod' i
s to y and save it in z */
printf("\n");
printf("%d\n", z);
printf("\n");
printf("%c\n", mod);
return 0;
}
using Microsoft Visual 6.0 Pro, in a Windows XP Pro environment
and the error:
2\mod.c(17) : error C2146: syntax error : missing ')' before identifier 'mod'
|