Skip to the task
Layout
Back to classic view

You are looking ahead. Your place is still task 1: About.

RUNTask 15 of 17 · step 4: Task 1: a row of numbersRun the practice-test tests
Run the practice-test tests in practice/04/

In CLion pick All CTest and ▶, or run only the practice-test tests in the terminal.

Checklist

  • Every task is one commit with a clear message.
  • Zero compiler warnings: the code builds with -Werror.
  • Once per topic you step through your code in the debugger (CLion, gdb).
  • Every function has preconditions and postconditions, and assert tests check them.
Details & hint
$ ctest --preset debug -L test1
    Start 75: test1_numbers_1
1/6 Test #75: test1_numbers_1 ..................***Failed    0.07 sec

=== test1_numbers_1: FAILED ===
The output differs on line 1.
  expected: |How many numbers? 6|
  got:      (the output ended)
  (\t = tab, ~ = a space at the end of the line)

You should see: While numbers.c is empty, the test1_numbers tests say "the output ended". When all is well, the three test1_numbers tests pass.

Stuck? The test shows a space at the end of a line as ~. Check a negative even number with % 2 == 0.

practice 04 main.c Code Diff
UNCHANGED This step does not change this file.
#include <stdio.h>
#include "input.h"
int main(void) {
int grade = read_int("Grade (0 - stop): ");
int sum = 0;
int count = 0;
while (grade != 0) {
sum += grade;
count++;
grade = read_int("Grade (0 - stop): ");
}
if (count > 0) {
printf("Average: %.2f\n", (double)sum / count);
} else {
printf("No grades.\n");
}
return 0;
}
opened for this task
$ ctest --preset debug -L test1
    Start 75: test1_numbers_1
1/6 Test #75: test1_numbers_1 ..................***Failed    0.07 sec

=== test1_numbers_1: FAILED ===
The output differs on line 1.
  expected: |How many numbers? 6|
  got:      (the output ended)
  (\t = tab, ~ = a space at the end of the line)