Commit 04ac6a5d by Karine

Exercise_05_06

parent 9daac871
exercise_05_06: main.o | .gitignore
g++ $^ -o $@
main.ii: main.cpp
g++ -E $^ -o $@
main.s: main.ii
g++ -S $^ -o $@
main.o: main.s
g++ -c $^ -o $@
.gitignore:
echo "exercise_05_06" > $@
clean:
rm *.ii *.s *.o *.out exercise_05_06 .gitignore
test: exercise_05_06
@./exercise_05_06 < test.in > test.out
@diff test.out test.expected > /dev/null 2>&1 && echo PASSED || echo FAILED
.PRECIOUS: main.ii main.s
.SECONDARY: main.ii main.s
#include <iostream>
int
main()
{
int sum = 0;
int count = 0;
std::cout << "Enter the numbers (9999 is the last number): ";
for (int i = 1; i > 0; ++i) {
int number;
std::cin >> number;
if (number == 9999) {
sum += number;
count++;
break;
}
sum += number;
count++;
}
double average = sum / count;
std::cout << "Average is " << average << std::endl;
return 0;
}
Enter the numbers (9999 is the last number): Average is 1286
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