Commit 9913d26f authored by Artak Yenokyan's avatar Artak Yenokyan

Merge branch 'exe_06_12' into 'master'

Exercise_06_12, Version1

See merge request bpcarm/trainings2017!1216
parents e2460f6d 540babc8
progname = exercise_06_12
CC = g++
CFLAGS = -Wall -Wextra -Werror -g3
$(progname): $(progname).o | .gitignore
$(CC) $(CFLAGS) $^ -o $@
%.ii: %.cpp
$(CC) -E $(CFLAGS) $< -o $@
%.s: %.ii
$(CC) -S $(CFLAGS) $< -o $@
%.o: %.s
$(CC) -c $(CFLAGS) $< -o $@
.gitignore:
echo $(progname) > $@
clean:
rm -f *.ii *.s *.o *.out $(progname) .gitignore
test: $(progname)
./$(progname) < $@.in > $@.out
diff $@.out $@.expected && echo PASSED || echo FAILED
.PRECIOUS: $(progname).ii $(progname).s
.SECONDARY: $(progname).ii $(progname).s
#include <iostream>
#include <cmath>
double
calculateCharges(const double hours)
{
double amount = 2;
if (hours > 3) {
amount = 2 + std::ceil(hours - 3) * 0.5;
}
if (amount > 10) {
amount = 10;
}
return amount;
}
int
main()
{
double totalHours = 0.0;
double totalAmount = 0.0;
for (int i = 1; i <= 3; ++i) {
double carHours;
std::cout << "Enter the parking hours of a car: ";
std::cin >> carHours;
std::cout << std::endl;
if (carHours < 0 || carHours > 24) {
std::cerr << "Error 1: Invalid hour." << std::endl;
return 1;
}
const double amount = calculateCharges(carHours);
totalHours += carHours;
totalAmount += amount;
std::cout << "Car:" << i << "\t"
<< "Hours:" << carHours << "\t"
<< "Charge:" << amount << std::endl
<< std::endl;
}
std::cout << "Total hours:" << totalHours << "\t" << "Total amount:" << totalAmount << std::endl;
return 0;
}
Enter the parking hours of a car:
Car:1 Hours:1.5 Charge:2
Enter the parking hours of a car:
Car:2 Hours:4 Charge:2.5
Enter the parking hours of a car:
Car:3 Hours:24 Charge:10
Total hours:29.5 Total amount:14.5
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment