C2143 errors

This is a discussion on C2143 errors within the C Programming forums, part of the General Programming Boards category; hi, im busy writing a c program that will allow a shop keeper to enter item prices, check if items ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    4

    C2143 errors

    hi,
    im busy writing a c program that will allow a shop keeper to enter item prices, check if items are vat or not, calculate vat as well as check if they are members and print out reciepts etc but with all my else statements there is this error where it says "syntax error c2143 missing ; before { but i cant put in a ; because it will make the statement empty! please help!!!

    here is the code:

    /* this program will allow user to enter price, check if its a VAT item or not, calculate tax if VAT,
    calculate final bill, check if customer is a member, and if so calculate discount, and calculate any
    change due.*/

    #include <stdio.h>
    #include <conio.h>

    int main()
    { /* declaring and initializing variables*/

    double vat = 0.10;
    double mem_discount = 0.05;
    double item_price;
    double tax = 0;
    double total_tax = 0;
    double subtotal = 0;
    double final_bill = 0;
    double mem_final_bill = 0;
    double money_paid;
    double change_due;
    double discount = 0;
    int member;
    int non_member;
    char vat_item;
    char nonvat_item;
    char y;
    char n;

    printf("welcome to De Corner Variety Shop\n");

    printf("enter item price, type -1 to end\n");
    scanf("%lf", &item_price);

    while (item_price != -1) /*while loop to allow user to enter as many items as they want and to enter a sentinel value when finished*/
    {
    subtotal += item_price; /*calculates running subtotal of all goods*/

    printf("enter y if item is a VAT item and n if item is a non vat item\n");
    scanf("%c", &vat_item);
    scanf("%c", &nonvat_item);

    if (vat_item == y)
    {
    tax = item_price * vat; /* calculates the vat owed on item*/

    total_tax += tax; /* calculates the total tax of all goods*/
    } // end if statement

    } // end while loop

    final_bill = subtotal + total_tax;

    printf(" the final bill before discount (if applicable) is %.2lf\n", final_bill);


    printf("enter 1 if customer is a member, 2 if a non member\n");
    scanf("%d", &member);
    scanf("%d", &non_member);

    if (member == 1)
    {
    discount = final_bill * mem_discount;

    mem_final_bill = final_bill - discount;

    printf("the total is $ %.2lf", mem_final_bill);

    printf("how much did the member pay?\n");
    scanf("%lf", &money_paid);

    if (money_paid > mem_final_bill)
    {
    change_due = money_paid - mem_final_bill;

    printf("$ %.2lf is owed to the customer\n", change_due);
    printf(" thank you and have a great day!\n");
    }
    Code:
    else (money_paid == mem_final_bill)
    			{ 
    				printf("no change is owed to the customer\n");
    				printf("thank you and have a great day!\n");
    			}
    }// end if statement
    Code:
    else(non_member == 2)
    		{ 
    			printf("the total is $ %.2lf\n", final_bill);
    			printf("how much did the customer pay?\n");
    if (money_paid > final_bill)
    {
    change_due = money_paid - final_bill;

    printf("$ %.2lf is owed to the customer\n", change_due);
    printf(" thank you and have a great day!\n");
    }
    Code:
    else (money_paid == final_bill)
    			{ 
    				printf("no change is owed to the customer\n");
    				printf("thank you and have a great day!\n");
    			}
    } // end else statement
    getchar();

    return 0;
    } // end main function

    any help really appreciated!!!

  2. #2
    cas
    cas is offline
    Registered User
    Join Date
    Sep 2007
    Posts
    957
    In the future, please wrap your entire program in code tags.

    You have to use "else if", not just "else". The general look is something like:
    Code:
    if(condition1) {}
    else if(condition2) {}
    else if(condition3) {}
    else {}

  3. #3
    Registered User
    Join Date
    Nov 2009
    Posts
    4
    thank you!!!
    makes sense now!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what am I missing? (Program won't compile)
    By steals10304 in forum C Programming
    Replies: 3
    Last Post: 08-25-2009, 03:01 PM
  2. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 02:49 PM
  3. Crazy errors caused by class, never seen before..
    By Shamino in forum C++ Programming
    Replies: 2
    Last Post: 06-10-2007, 11:54 AM
  4. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  5. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 03:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21