0

In this program i want to ask the cashier if the customer wants to buy anything else. Typically,

Ask customer what beef product he wants to buy.
Ex. 1 //Chicken Liver
Ask customer how many kilo(s) he will buy.
Ex. 2 //2kg

(problem)
Then ask the customer if he wants to buy another product. "y or n"
if y -->Then ask again the customer what beef product he wants.
if n --> proceed.


I still don't know to do that.
We haven't taught about it yet.

This is just a part of my very long code hehe...
@_@ im still a newbie.

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


int main()
{
    int aChoice,bChoice,cChoice,kg, i = 1;
    float tax = .12,cash;
    float total = 0,change = 0;
    float bill = 0,taxAmount = 0;
    
    while ( i != 0)
    {
           
  
  
          system("color 8");
          printf("\n                      %c%c%c Welcome to MACEED Meat Shop\n\n",195,180,179);
          printf("               %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",201,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,187);
          printf("               %c What kind of meat product do you want to buy?%c\n\n",186,186);
          
          printf("               %c",186);
          
          printf("   [1] Chicken \t  [2] Pork\t[3] Beef      %c\n",186);
          
          printf("               %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",200,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,188);
          
          printf("\n\n\n               Choice: ");
          scanf("%d",&aChoice);
          system("CLS");
    
          
          if (aChoice==3)
          {
                system("color 2");
                printf("\t\t\t%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",220,220,220,220,220,220,220,220,220,220,220,220,220,220,220,220,220,220,220,220,220,220,220,220,220,220,220,220,220,220,220,220);
                printf("\t\t\t%c            Beef              %c\n",219,219);
                printf("\t\t\t%c------------------------------%c\n",219,219);
                printf("\t\t\t%c[1]Beef Cubes          P240/kg%c\n",219,219);
                printf("\t\t\t%c[2]Bones               P150/kg%c\n",219,219);
                printf("\t\t\t%c[0]Exit                to exit%c\n",219,219);
                printf("\t\t\t%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223);
                
                printf("\t\t\tNumber of item: ");
                scanf("%d",&bChoice);     
          
                
                 if(bChoice==1 )
                {
                     printf("\n\n");
                     printf("\t\t\tPurchasing Beef Cubes\n\n\n");
                     
                     printf("How many kilogram(s): ");
                     scanf("%d",&kg);
              
                     while(kg <= 0 )
                     {
                           printf("Please enter a positive number: ");
                           scanf("%d",&kg);
                     }
                     
                     bill = kg*240;
                     printf("\nBill                     %c P%.2f",205,bill);
                     taxAmount = bill * tax;
                     printf("\nTax Amount:              %c P%.2f",205,taxAmount);
                     
                     
                     printf("\nAmount of customers cash tendered: P");
                     scanf("%f",&cash);
                     
                     
                     while (cash < bill)
                     {
                              printf("Insufficient fund!");
                              printf("\nPlease enter the amount again: P");
                              scanf("%f",&cash);
                              change = cash - bill;
                              printf("\nChange: P%.2f\n",change);
                              system("CLS");
                     
                     }
                     if (cash >= total)
                     {
                              change = cash - bill;
                              printf("\nChange: P%.2f\n",change);
                             
                     }
                system("CLS");
                
                printf("\n\n\n");
                printf("\t\t\t%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n\n",177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177);
                printf("\t\t\t%c Tax  : P%.2f  %c\n",177,taxAmount,177);
                printf("\t\t\t%c Bill: P%.2f  %c\n",177,bill,177);
                printf("\t\t\t%c -------------- %c\n",177,177);
                printf("\t\t\t%c Cash: P%.2f  %c\n",177,cash,177);
                printf("\t\t\t%c ============== %c\n",177,177);
                printf("\t\t\t%c Change:P%.2f  %c\n\n\n\n",177,change,177);
          
                system("PAUSE");
                system("CLS");     
                }
                if(bChoice==2 )
                {
                     printf("\n\n");
                     printf("\t\t\tPurchasing Bones\n\n\n");
                     
                     printf("How many kilogram(s): ");
                     scanf("%d",&kg);
              
              /* Basically, this' where the part i want to ask if the customer
              wants to buy anything else.*/
                     while(kg <= 0 )
                     {
                           printf("Please enter a positive number: ");
                           scanf("%d",&kg);
                     }
                     
                     bill = kg*150;
                     printf("\nBill                     %c P%.2f",205,bill);
                     taxAmount = bill * tax;
                     printf("\nTax Amount:              %c P%.2f",205,taxAmount);
                     
                     
                     printf("\nAmount of customers cash tendered: P");
                     scanf("%f",&cash);
                     
                     
                     while (cash < bill)
                     {
                              printf("Insufficient fund!");
                              printf("\nPlease enter the amount again: P");
                              scanf("%f",&cash);
                              change = cash - bill;
                              printf("\nChange: P%.2f\n",change);
                              system("CLS");
                     
                     }
                     if (cash >= total)
                     {
                              change = cash - bill;
                              printf("\nChange: P%.2f\n",change);
                             
                     }
                system("CLS");
                
                printf("\n\n\n");
                printf("\t\t\t%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n\n",177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177);
                printf("\t\t\t%c Tax  : P%.2f  %c\n",177,taxAmount,177);
                printf("\t\t\t%c Bill: P%.2f  %c\n",177,bill,177);
                printf("\t\t\t%c -------------- %c\n",177,177);
                printf("\t\t\t%c Cash: P%.2f  %c\n",177,cash,177);
                printf("\t\t\t%c ============== %c\n",177,177);
                printf("\t\t\t%c Change:P%.2f  %c\n\n\n\n",177,change,177);
          
                system("PAUSE");
                system("CLS");     
                }
                if(bChoice == 0 && bChoice ==1)
                {
                system("CLS");      
                }
                else
                system("CLS");
          
              }
          /*system("CLS");
          
          printf("Bill : P%.2f\n",bill);
          printf("Tax  : P%.2f\n",taxAmount);
          printf("Total: P%.2f\n",total);
          printf("Cash : P%.2f\n\n",cash);
          printf("Change:P%.2f\n\n\n\n",change);
          
          system("PAUSE");
          system("CLS");*/
          i++;
          }
          
          getchar();
          getchar();
          return 0;
}
2
Contributors
1
Reply
7
Views
7 Years
Discussion Span
Last Post by abhi.navale
0

I made a rough algorithm from given program.

  1. Take inputs from user.
  2. Do calculations.
  3. Print the result.

I suggest you to add do...while loop as follows =>

do
{

    //code

Then ask the customer if he wants to buy another product. "y or n"
if y -->Then ask again the customer what beef product he wants.
if n --> proceed.
//this prompt will be at very end inside this do....while loop
//this loop will repeat until customer says 'NO'.
   }while(condition);//dont forget this semicolon!!!
//if customer says 'NO' then you will come out of the loop here...
2. Do the calculations
3. Print result.

Edited by mike_2000_17: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.