Hello everyone..im new here and seeking help..hope you guys can help me..
I got this question and need to this in modular programming ( i need to create my own library and source file)
You need to create a simple C++ code at one restaurant. The program should ask you to input menu code and the amount for each menu.The program should keep on asking for menu code until the cashier enter -1 to indicate the end of order list.At the end, the program will print the total need to pay including calculation below.
- service charge of 10% per receipt
- government tax of 5%
- rounding off to the nearest 0.00 or 0.05 according to the new government regulation.
for (loop=0;loop>=0;loop++) will continue while loop is greater or equal to 0 but if you set it to 0 at start you will have to wait until its value is wrapped over the maximum to negative values
I suppose if (code =! -1) should be if (code != -1)
Why is your main function implementation in the header?
Hahaha..because in my class..the lecturer teach me implement main function in header much easier..I don't know which one easier. I just do how my lecturer teach me. Will you help me create this code for me? Because i already stuck
Actually i not sure because the variable code need to accept 2 type ( int and char).. now i still stuck here and can't continue..this assignment quite tough for me
#include <stdio.h>
#include "pay.h"
#define BB 2.00
#define HH 2.00
#define FF 1.30
#define CC 1.50
#define PP 1.50
int total_menu,amount,total_all,total_pay,loop;
int code;
int main ()
{
printf ("Please enter menu code shown as below:\n");
printf ("Burger = BB\n");
printf ("Hot Dog =HH\n");
printf ("French Fries =FF\n");
printf ("Coca cola =CC\n");
printf ("Pepsi = PP\n");
printf ("Press -1 to stop\n\n");
for (loop=1;loop<=10,code!=-1;loop++)
{
printf ("Enter the code foods/drinks here:");
scanf ("%s",&code);
if (code!=-1)
{
printf ("Enter the amount foods/drinks here:");
scanf ("%d",&amount);
total_menu=code*amount;
total_all=total_all+total_menu;
printf ("Total:%d\n",total_menu);
}
elseif (code==-1)
{
all_pay(total_all);
}
else
{
printf ("Wrong code");
}
}
}
1 2 3 4 5 6 7 8 9 10 11 12
void all_pay (int total_all)
{
double service_charge,gov_tax,overall;
service_charge=total_all*0.1;
gov_tax=total_all*0.05;
overall=total_all+service_charge+gov_tax;
printf ("The total is :%d\n",overall);
}
It be will i show above.
Now my problem is
1. After I enter code for example BB then the program ask me the amount..But when to print the total, the value is incorrect.
2.Even I enter code "-1", the program still asking the amount. Suppose when I enter "-1", the program should stop and calculate the overall total. (To calculate the overall total is in my header file).
Guys please help me! Correct me..I already 3 days less sleep..This program so tough for newbie like me..Soo sad!
You are trying to put a code such as 'BB' (as string) into an integer!
This will get you more on course, but still you need to address how you get input from the user (this will loop out of controll if a letter is used instead of numbers).
Yes, bool means boolean and it can take the value "false" (== 0) and "true" (any other number).
What compiler do you use? Some old compilers don't work with bool. But you can define a simple kind of bool by adding these lines to the top of your program:
Sorry i forgot to mention this.. the program not complete yet..
- rounding off to the nearest 0.00 or 0.05 according to the new government regulation.
0.06>>0.07 will round to 0.05, 0.08>>0.09 will round to 0.10
0.01>>0.02 will round to 0.00, 0.03>>0.04 will round to 0.05
example
$1.37 will $be 1.35
$1.38 will $be 1.40
$1.33 will $be 1.35
$1.32 will $be 1.30