Commit 8491c6a0 authored by Believer Programmers' Club's avatar Believer Programmers' Club

Merge branch 'exercise_05_14' into 'master'

Mary Zaqaryan Exercise_05_14 Version2

See merge request bpcarm/trainings2017!1357
parents 0e05e92f 4da5dfb7
#include <iostream>
int
main()
{
double sum = 0;
for (int i = 0; i < 5; ++i) {
int productNumber;
std::cin >> productNumber;
int productAmount;
std::cin >> productAmount;
if (productAmount < 0) {
std::cerr << "Error 1: Amount can't be negative.";
return 1;
}
switch (productNumber) {
case 1: sum += productAmount * 2.98; break;
case 2: sum += productAmount * 4.50; break;
case 3: sum += productAmount * 9.98; break;
case 4: sum += productAmount * 4.49; break;
case 5: sum += productAmount * 6.87; break;
default: std::cerr << "Error 2: Invalid product number"; return 2;
}
}
std::cout << "Sum: " << sum << std::endl;
return 0;
}
exercise_05_14: exercise_05_14.o | .gitignore
g++ $^ -o $@
exercise_05_14.ii: exercise_05_14.cpp
g++ -E $^ -o $@
exercise_05_14.s: exercise_05_14.ii
g++ -S $^ -o $@
exercise_05_14.o: exercise_05_14.s
g++ -c $^ -o $@
.gitignore:
echo "exercise_05_14" > $@
removes:
rm *.ii *.s *.o *.out exercise_05_14 .gitignore
test: exercise_05_14
./exercise_05_14 < test.in > test.out
diff test.out test.expected > /dev/null 2>&1 && echo PASSED || echo FAILED
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