-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCasey.c
110 lines (91 loc) · 3.05 KB
/
Casey.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* CS2600 Project 2
* Functions written by @Casey Merritt
*/
#include <stdio.h>
#include "header.h"
/* Asks user for total airfare cost and returns that value*/
float airfare() {
float airfare;
int cont = 1;
while (cont == 1) {
printf("Enter RoundTrip Airfare: $");
scanf("%f", &airfare);
if(airfare < 0) {//checking for positive values only
printf("\n");
printf("Value must be greater than 0, try again\n");
printf("\n");
}else {
cont = 0;
}
}
return airfare;
}
/* Asks user for total registration cost and returns that value */
float conferenceFees() {
int cont = 1;
float registrationCost;
while (cont == 1) {
printf("Enter total amount of registration fees: $");
scanf("%f", ®istrationCost);
if (registrationCost < 0) {//checking to make sure only positive values are accepted
printf("\n");
printf("Value must be greater than 0, try again\n");
printf("\n");
}
else {
cont = 0;
}
}
return registrationCost;
}
/* Asks user for hotel daily rate and calculate total cost*/
float hotelFees(int days) {
float hotelFees;
int cont = 1;
while (cont) {
printf("Enter Hotel Cost Per Day: $");
scanf("%f", &hotelFees);
if (hotelFees < 0) {//checking to make sure positive values only are accepted
printf("\n");
printf("Value must be greater than 0, try again\n");
printf("\n");
}
else {
cont = 0;
}
}
return (hotelFees * days);
}
/*
* Calculates the difference between allowable trip amount and total trip amount
* Function should only be called if total is greater than allowable otherwise return value will be invalid
*/
float amountSaved(float allowable, float total){
if(total > allowable){
printf("Something is broken");//this function should not be called if the total is greater than allowable call the excess function instead
return -1;
}else if(total == allowable){
//printf("the trip cost is equal to the total allowable trip cost");
return 0;
}else{
printf("Amount that was saved by the company: $%.2f\n", (allowable - total));
return (allowable - total);
}
}
/*
* Calculates the difference between total trip amount and allowable trip amount
* Function should only be called if total is less than allowable otherwise return value will be invalid
*/
float amountExcess(float allowable, float total){
if(total < allowable){
printf("Something is broken");//this function should not be called if the total is less than allowable, call the saved function instead
return -1;
}else if(total == allowable){
printf("the trip cost is equal to the total allowable trip cost\n");
return 0;
}else{
printf("Amount that needs to be reimbursed to the company: $%.2f\n", (total - allowable));
return (total - allowable);
}
}