• C

line 26: Parse Error, expecting `NUMBER'

I am trying to figure where my error is coming from.  This program is supposed to give the equivalents of five currencies in USD.  Here is the code:

#include <stdio.h>
main ()
      float ad;
      float cd;
      float dk;
      float nk;
      float tb;
      int ans;
            printf("***** CURRENCY CONVERTER *****");
            printf("1 - Australian Dollars \n");
            printf("2 - Canadian Dollars \n");
            printf("3 - Danish Krone \n");
            printf("4 - Norwegian Kroner \n");
            printf("5 - Thai Bhat \n\n");
            scanf(" %d", &ans);
            while ((ans!='1')&&(ans!='2')&&(ans!='3')&&
      switch (ans)
            case ('1') : {ad = 1.38274;
                        printf("\n The equivalent in US Dollars is %.2f", ad);
            case ('2') : {cd = 1.2629;
                        printf("\n The equivalent in US Dollars is %.2f", cd);
            case ('3') : {dk = 6.001;
                        printf("\n The equivalent in US Dollars is %.2f", dk);
            case ('4') : {nk = 6.692;
                        printf("\n The equivalent is US Dollars is %.2f", nk);
            case ('5') : {tb = 41.36;
                        printf("\n The equivalent is US Dollars is %.2f", tb);
Who is Participating?

Improve company productivity with a Business Account.Sign Up

ankuratvbConnect With a Mentor Commented:
Do-While requires a semi-colon at the end of while.

The problem is the quotes surrounding the integer values 1-5;

Your while statement should be something like:

while ((ans!=1)&&(ans!=2)&&(ans!=3)&&
Similarly,remove the single quotes from the case statements as well.

case 1:

case 2:

Kent OlsenData Warehouse Architect / DBACommented:

The code isn't particularly well structured, and that's probably leading to the "hiding" of this problem.

Take the ';' off of the while() statement.  You're probably seeing an "infinite loop" and this is the reason.

Good Luck,
Couple notes:

main should be declared as either
int main() or int main(int argc, char **argv)

Also you variable ans is declared as an int.  Therefore in your while loop you should not be comparing it against characters.  For instance, it should be while(ans != 1) not while(ans != '1').
Also you while loop is pretty worthless as it stand since it is considered empty.  The structure of a while loop should be:

You while loop currently looks like:

Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

Since there is a 'do' statement preceding the while I do think the ';' is neccessary
My compiler says to use:

     double ad;
     double cd;
     double dk;
     double nk;
     double tb;


Hi Kdo,
> The code isn't particularly well structured

Good point.
JJ7717, you have a lot of redundancy here. Think about using an array of structs instead:

struct currency{
    char* name;
    char* short_name;
    double rate;

then you can define all your currencies nicely:

struct currency all_currencies[]={
    {"Australian Dollar", "AUD", 1.38274},
    {"Euro", "EUR", 0.85345435},

...now you should know how to proceed: Loop to print the choices, do the appropriate calculations, etc.


JJ7717Author Commented:
Thanks to everyone who commented on my problem.  I will put together the suggestions and retool my program.

The parse error you have is particularly because of the LPAREN `(' character found after the case keyword. The compiler interprets the value after the `case' as a number. And, hence, the Left parentheses you have is unexpected for the compiler.

When you enclose a digit number between single quotes in the case statement like (case '2': ), this is perfectly legal. However, their actual value is not 2 but actually the ASCII code number for the character 2, which is in fact  50. Which can be very misleading and "hidden" in your program.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.