Hey I started using this site to learn C yesterday, and I got to the chapter on functions and decided to try and make a little program to do simple calculations.
This is the what I've written so far;
However I can't seem to make it work, I get an error on the lines with the if statements saying; "syntax error before ')' token.Code:#include <stdio.h> int calc ( int x, int y ); int main() { int x; char f; int y; printf( "Please input a number: " ); scanf( "%d", &x ); printf("Please choose a function(add, subtract, divide, or multiply):"); scanf("%c", f ); printf( "Please input a second number: " ); scanf( "%d", &y ); if (f == *); { printf( "The product of your two numbers is %d\n", mult( x, y ) ); } else if (f == +); { printf( "The product of your two numbers is %d\n", add( x, y ) ); } else if (f == /); { printf( "The product of your two numbers is %d\n", divide( x, y ) ); } else (f == -); { printf( "The product of your two numbers is %d\n", subtract( x, y ) ); } getchar(); } int mult (int x, int y) { return x * y; } int add (int x, int y) { return x + y; } int subtract (int x, int y) { return x - y; } int divide (int x, int y) { return x / y; }
Can anyone help? Thanks



LinkBack URL
About LinkBacks


