-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPractice problems 1
48 lines (33 loc) · 1001 Bytes
/
Practice problems 1
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// DEBUG
// Become familiar wih C syntax
// Learn to debug buggy code
#include <cs50.h>
#include <stdio.h>
int main(void)
{
// Ask for your name and where live
string name = get_string("What is your name? ");
string location = get_string("Where do you live? ");
// Say hello
printf("Hello, %s, from %s!", name, location);
}
// HALF
// Calculate your half of a restaurant bill
// Data types, operations, type casting, return value
#include <cs50.h>
#include <stdio.h>
float half(float bill, float tax, int tip);
int main(void)
{
float bill_amount = get_float("Bill before tax and tip: ");
float tax_percent = get_float("Sale Tax Percent: ");
int tip_percent = get_int("Tip percent: ");
printf("You will owe $%.2f each!\n", half(bill_amount, tax_percent, tip_percent));
}
// TODO: Complete the function
float half(float bill, float tax, int tip)
{
float total = bill * ( 1 + tax/100.0);
total = total * (1 + tip/ 100.0);
return total /2;
}