Mac Parse error beofore ")" token

Quboid

macrumors 6502
Original poster
Oct 16, 2006
441
0
everywhere
Hey,
I'm new to programming in C, and i have been having a problem with a simple program that i recently coded. Xcode is giving me parse error message for an "if" line that i can almost swear is right. Check it out.

#include<stdio.h>
#include<math.h>
int a, b, d, e, f ;
char c;

int main (void)
{
printf("enter a number");
scanf("%i",&a);
printf("enter another number");
scanf("%i",&b);
Printf("this is the menu");
Printf("\n 1. *");
printf("\n 2. +");
printf("\n 3. -");
printf("\n 4. /");
printf("\n 5. %");
printf("\n 6. ^");
scanf("%char",&c);

if(c==*){
d=a*b;
}
if(c==+){
d=a+b;}

the error message is "parse error before ")" token. I am not sure what the error is , but i've tried eveything i could, can someone help me out? i have an exam soon and i want to be up to mark.
Thanks..
 

iMeowbot

macrumors G3
Aug 30, 2003
8,634
0
if(c==*){

and

if(c==+){

are your immediate problems.

Since you are trying to compare chars, you need to put '*' and '+' inside single quotes.

The last scanf() is going to need work too, you will want to look a little more closely at the function documentation.
 

dcv

macrumors G3
May 24, 2005
8,021
1
It's years since I looked at C but surely you need to enclose the string literal in quotes?

Code:
		if(c==[color=red]"[/color]*[color=red]"[/color]){
		d=a*b;
		}
		if(c==[color=red]"[/color]+[color=red]"[/color]){
		d=a+b;}

(sorry can't quite remember if it's double or single quotes you need though)
 

bbarnhart

macrumors 6502a
Jan 16, 2002
824
1
I see three issues:

1. printf is spelled with a capitol p in some cases.

2. if (c==*) should be if (c == '*')

3. The main function is missing a closing curly bracket.
 

bousozoku

Moderator emeritus
Jun 25, 2002
13,973
3
Gone but not forgotten.
dcv said:
It's years since I looked at C but surely you need to enclose the string literal in quotes?

Code:
		if(c==[color=red]"[/color]*[color=red]"[/color]){
		d=a*b;
		}
		if(c==[color=red]"[/color]+[color=red]"[/color]){
		d=a+b;}

(sorry can't quite remember if it's double or single quotes you need though)
Quotation marks for strings of characters and apostrophes for single characters.
 

Soulstorm

macrumors 68000
Feb 1, 2005
1,887
1
Oh, and... please use code tags. Not using them will result in frustration of every programmer here trying to figure out what you write in the code, since there is no identation outside code tags.
 

HiRez

macrumors 603
Jan 6, 2004
5,848
1,803
Western US
It's also helpful to point out which line it gave you the error in (copying and pasting the debugger messages can help too). That way we know where in your code to start looking.
 

dernhelm

macrumors 68000
May 20, 2002
1,641
117
middle earth
iMeowbot said:
if(c==*){

and

if(c==+){

are your immediate problems.

Since you are trying to compare chars, you need to put '*' and '+' inside single quotes.

The last scanf() is going to need work too, you will want to look a little more closely at the function documentation.
And it is never too early to learn that are ignoring return values of functions at your own risk...
 

jlcharles

macrumors 6502
Mar 30, 2006
345
0
Wenonah, NJ
If you give a menu with numbers, why are you checking for the symbol? Wouldn't it make more sense to make c an int?

And then, by using a menu like that, I prefer to use a case statement.
 

ATG

macrumors regular
Aug 7, 2005
187
0
And then, by using a menu like that, I prefer to use a case statement.
It's normally best for new programmers to develop their own style - not some else's. Unless it's generally accepted to do it the other way for a very good reason.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.