Hi guys, 1st year cllege student here. New on C Programming. My program's main unction is that it will display products with fixed cost and a person will just enter numbers and will be multiplied to the fixed cost. The product of those should be displayed correctly but in my program, it doesn't, Please help me this is for my school project :)

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


buyfood(void);
exit(void);

main()

 char choice;
 clrscr();
 textcolor(GREEN);
 gotoxy(19,4);
 cprintf("++++++++++++++++++++++++++++++++++++");
 textcolor(WHITE);
 gotoxy(23,5);
 cprintf("Welcome to Arabic Food Store!");
 textcolor(GREEN);
 gotoxy(19,6);
 cprintf("++++++++++++++++++++++++++++++++++++");

 textcolor(WHITE);
 gotoxy(19,9);
 cprintf("What do you want to do?");
 gotoxy(19,11);
 cprintf("a. Buy");
 gotoxy(19,13);
 cprintf("b. Exit");

 textcolor(GREEN);
 gotoxy(19,15);
 cprintf("--->  ");
 scanf("%c",&choice);

    switch (choice)
      {
     case 'a':        buyfood();
            break;
     case 'b':        exit();
            break;
     default:       main();
      }


getch();
return (main());
}
buyfood(void)
{
 clrscr();
 char y;
 int croissant,tamis,tamiswcheese,falafil,cocktail,pepsi,water;
 int c,t,tc,f,cock,p,w;
 int c1,t1,tc1,f1,cock1,p1,w1;
 int total;

 croissant=2;
 tamis=5;
 tamiswcheese=7;
 falafil=5;
 cocktail=5;
 pepsi=2;
 water=1;
 total=c1+t1+tc1+f1+cock1+p1+w1;

 textcolor(YELLOW);
 gotoxy(15,4);
 cprintf("We offer you:                 Price   How many    Cost ");

 textcolor(YELLOW);
 gotoxy(15,7);
 cprintf("1. Croissant                   2 SR       ");
 cscanf("%d",&c);
 gotoxy(65,7);
  c1=croissant*c;
 cprintf("%d SR",c1);
 getch();

 textcolor(YELLOW);
 gotoxy(15,9);
 cprintf("2. Tamis                       5 SR       ");
 cscanf("%d",&t);
 gotoxy(65,9);
  t1=tamis*t;
 cprintf("%d SR",t1);
 getch();


 textcolor(YELLOW);
 gotoxy(15,11);
 cprintf("3. Tamis w/ Cheese             7 SR       ");
 cscanf("%d",&tc);
 gotoxy(65,11);
  tc1=tamiswcheese*tc;
 cprintf("%d SR",tc1);
 getch();


 textcolor(YELLOW);
 gotoxy(15,13);
 cprintf("4. Falafil                     5 SR       ");
 cscanf("%d",&f);
 gotoxy(65,13);
  f1=falafil*f;
 cprintf("%d SR",f1);
 getch();


 textcolor(YELLOW);
 gotoxy(15,15);
 cprintf("5. Cocktail                    5 SR       ");
 cscanf("%d",&c);
 gotoxy(65,15);
  c1=cocktail*c;
 cprintf("%d SR",c1);
 getch();


 textcolor(YELLOW);
 gotoxy(15,17);
 cprintf("6. Softdrinks (Any)            2 SR       ");
 cscanf("%d",&p);
 gotoxy(65,17);
  p1=pepsi*p;
 cprintf("%d SR",p1);
 getch();

 textcolor(YELLOW);
 gotoxy(15,19);
 cprintf("7. Water                       1 SR       ");
 cscanf("%d",&w);
 gotoxy(65,19);
  w1=water*w;
 cprintf("%d SR",w1);
 getch();

 textcolor(YELLOW);
 gotoxy(55,21);
 cprintf("Total: %d SR", total);
 getch();

 gotoxy(40,23);
 cprintf("Do you want to exit? (y/n)  ");
 cscanf("%c",&y);
 getch();

  if (y=='y' || y=='Y')
     {   exit();}
  if (y=='n' || y=='N')
     {return (main()); }
  else
     textcolor(WHITE);
     gotoxy(46,24);
     cprintf("INVALID!!");
     getch();
     return (buyfood());
}

exit(void)
{
 clrscr();
 textcolor(GREEN);
 gotoxy(19,4);
 cprintf("++++++++++++++++++++++++++++++++++++");
 textcolor(WHITE);
 gotoxy(26,5);
 cprintf("Thank You For Shopping!");
 textcolor(GREEN);
 gotoxy(19,6);
 cprintf("++++++++++++++++++++++++++++++++++++");
 textcolor(WHITE);
 gotoxy(19,12);
 cprintf("PROGRAMMERS:            EDRIAN DERAY");
 gotoxy(19,13);
 cprintf("                      AHMAD MOHAMMAD");
 gotoxy(19,14);
 cprintf("                       MAJED PAYAWAL");
 gotoxy(19,15);
 cprintf("                        DARYL MACUHA");


 getch();
 exit(0);

}

{

errors exist due to following reasons:
exit() is already defined in stdlib.h . so rename it.

clrscr();
char y;
int croissant,tamis,tamiswcheese,falafil,cocktail,pepsi,water;
int c,t,tc,f,cock,p,w;
int c1,t1,tc1,f1,cock1,p1,w1;
int total;

declaration part take place before clrscr(); so write this as :

 char y;
 int croissant,tamis,tamiswcheese,falafil,cocktail,pepsi,water;
 int c,t,tc,f,cock,p,w;
 int c1,t1,tc1,f1,cock1,p1,w1;
 int total;
 clrscr();

also remove opening curly brace at line 188.

c1=cocktail*c; shoule be cock1=cocktail*c;

remove line 65 and put it after line 139 put this:

total=c1+t1+tc1+f1+cock1+p1+w1;

Edited 3 Years Ago by Learner010

This article has been dead for over six months. Start a new discussion instead.