hi pls gelp me with my assignment.. i supposed to create a cash register program that will calculate customer's payment and change..
here's what i have so far..

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

int main(void)
{

printf("Welcome to Reddish Bar&Cafe");
printf("\n\n\Choose from the items below:");

printf("\n\n\n\Margarita= 25 bucks");
printf("\n\Beer= 10 bucks");
printf("\n\Martini= 35 bucks");
printf("\n\Rhum= 20 bucks");
printf("\n\Tequilla= 25 bucks");
printf("\n\Shots= 10 bucks");

{
int a, answer, yes;
    
    printf("\n\n\ enter first item;");
    scanf("%d",&a);

    printf("do you want to add another another item?");
    answer=0;
    do{
        printf(" yes or no? ");
        scanf("%d",&answer);
        } 
        while(answer==yes);
        printf("\n\n\please enter another item");
}
printf("\n\n\n\Thank you and come back again!!");


return 0;
}

i cannot push thru.. i dont know to calculate as well. please help
thanks!!

Edited 6 Years Ago by Nick Evan: Added code-tags

1) check that the customer has given you an amount exceeding his bill

2) use this equation: amount given - bill equals change due back to the customer

imo the easy way to deal with money is to multiply it all by 100, in order to eliminate any amount less than one (pennies are now dollars). Then do all the math making your change, (a while (change > 0) loop with every denomination of change inside it, is perhaps easiest to understand), and finally, print out the final bills, and use %.2d to print the coins (which you will have added up and know that they are less than 100 in value).

There is a sweet math way to do this, but it's harder to figure out.

Work on that, and post up your revised code. USE CODE TAGS AROUND YOUR PROGRAM CODE (highlight your code and click on the [code] icon in the editor window).

People won't study code that is all smashed up like html text.

thanks.. il try to work on this, this is pretty hard and making me really sleepless.. pls correct my codes once im done.. thanks!!!

You're welcome, and I will. The first thing is to stop and think how YOU would make change - step by step - what is that process?

That's your pseudo code (logic outline), for the program.

Right! We'll just need 4 instantiations of the coin class, and 4 more of the class dollar_bill. Then we'll need an inherited object of these two classes, for the bill and the change due.

You'd have to decide what will be private data, and what will be public data, for each of the above, and their relative worth assigned.

Then, at last, you'll get down to doing the very same arithmetic that you'd do in a procedural language! ;)

OOP is good for a lot of things, but it has no easy answers in this case.

hi.. i revised it but its still not running properly.. can you check it?

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


#define Margarita 25
#define Beer 10
#define Martini 35
#define Rhum 20
#define Tequilla 25
#define Shots 10


void main(void)

{
     int a=0, b=0, c=0, d=0, e=0, f=0, p=0;
     float amount_a=0, amount_b=0, amount_c=0, amount_d=0, amount_e=0, amount_f=0, amount=0, payment=0,change=0;
     char x, z;

do
{
clrscr();
printf("\nWelcome to Reddish Bar&Cafe");
printf("\n\n\Choose the  letter of your choice:");

printf("\n\a.   Margarita= 25 bucks");
printf("\n\b.   Beer= 10 bucks");
printf("\n\c.   Martini= 35 bucks");
printf("\n\d.   Rhum= 20 bucks");
printf("\n\e.   Tequilla= 25 bucks");
printf("\n\f.   Shots= 10 bucks");


    printf("\n\n\ Your order please?..");
    x=getch();
    printf("\n\nYou ordered %c",&x);
    printf("\n\n\ How many bottles do you want to buy?:");
    scanf("%d",&p);
    printf("\n\n\ Do you have another order?..[y/n]");
    z=getch();


if (x=='a'||x=='A')
   a=a+p;

else if (x=='b'||x=='B')
   b=b+p;

else if (x=='c'||x=='C')
   c=c+p;

else if (x=='d'||x=='D')
   d=d+p;

else if (x=='e'||x=='E')
   e=e+p;

else if (x=='f'||x=='F')
   f=f+p;

/*getch(); */
}

while(z=='y'||z=='Y');

             amount_a=Margarita*p;
             amount_b=Beer*p;
             amount_c=Martini*p;
             amount_d=Rhum*p;
             amount_e=Tequilla*p;
             amount_f=Shots*p;

printf("\n\n\ Your bill is as follows:");


if (amount_a>0)
   printf("\n\n\ %d bottles of Margarita is %f", &a, &amount_a);

else if (amount_b>0)
     printf("\n\n\ %d bottles of Beer is %f", &b, &amount_b);

else if (amount_c>0)
     printf("\n\n\ %d bottles of Martini is %f", &c, &amount_c);

else if (amount_d>0)
     printf("\n\n\ %d bottles of Rhum is %f", &d, &amount_d);

else if (amount_e>0)
     printf("\n\n\ %d bottles of Rhum is %f", &e, &amount_e);

else if (amount_f>0)
     printf("\n\n\ %d bottles of Shots is %f", &f, &amount_f);

getch();




amount=amount_a+amount_b+amount_c+amount_d+amount_e+amount_f;

printf("\n\n\your total bill is %f", &amount);

printf("\n\n\You gave %f", &payment);

change=payment-amount;

printf("\n\n\your change is %f", &change);

getch();

}

Edited 3 Years Ago by Dani: Formatting fixed

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