tip calculator

The waitstaff at a restaurant would like to determine the percentage (20%?, 15%?) left as tip by each customer. For comparison, the staff would also like to see how much the standard tip should be for a bill (e.g., $20 on $100).
left as tip and standard tip amount to be based on a customer’s total bill.

plz help how to do this?
Last edited on
what's your problem? math calculation? or how to code it?

I just can figure something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//percentage.cpp
//tip calculator

#include <iostream>
using std::cout;
using std::cin;
using std::endl;

double getTipPercentage(double total);

int main(){

int total;

cout<<"Enter total bill to calculate tip: ";
cin>>total;
cout<<"Total :"<<total<<'\n'
	<<"Tip: "<<getTipPercentage(total)<<endl;


return 0; //indicates success
}//end main

double getTipPercentage(double total){
	double tip;
		tip=total*0.20;
return tip;
}//end function getTipPercentage 



Eyenrique-MacBook-Pro:Study Eyenrique$ ./percentage 
Enter total bill to calculate tip: 120
Total :120
Tip: 24
Last edited on
math calculation, how would i code this in C?
C is not equal to C++

do you -mandatory- have to use stdio.h functions? (printf(),scanf())

because in C++ you -normally- use the iostream library and use cout and cin objects!
Last edited on
yes i have to use stdio.h functions. include printf, scanf
To be honest i don't remember so much about C, but i can figure out this:
-i don't know how to control decimal precision in C-
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//percentage.c
//tip calculator

#include <stdio.h>

float getTipPercentage(float total);

int main(){

float total;
float tip;

printf("Enter total bill to calculate tip: ");
scanf("%f",&total);
tip=getTipPercentage(total);
printf("\nTotal: %f ",total);
printf("\nTip: %f ",tip);
printf("\n");

return 0; //indicates success
}//end main

float getTipPercentage(float total){
	float tip;
	float perc=0.20;
		tip=total*perc;
return tip;
}//end function getTipPercentage



Enter total bill to calculate tip: 120

Total: 120.000000 
Tip: 24.000000
well, you were a lot more help then any other coder, thank you so much...
You are welcome!
can you help to me?
Allow private messages on Account settings to send to you a private message.
ok, i changed it.
Topic archived. No new replies allowed.