Adding a new C program question

Adding a new C program question

von Vandana Naik -
Anzahl Antworten: 4

Can anyone help me by explaining how to write test case for simple c programs

Als Antwort auf Vandana Naik

Re: Adding a new C program question

von Richard Lobb -

The build-in c_program question type assumes that the student's program will read standard input and generate some standard output. So each test case simply defines the standard input plus the expected standard output. Additional data files can be supplied via the Support files section of the question editing form - these are all loaded into the working directory before the program is run.

Als Antwort auf Richard Lobb

Re: Adding a new C program question

von Vandana Naik -
Thank You  Richard Lobb !

Apologies for not properly putting up my query in earlier message. I was actually stuck at the point as what is to be entered in the first test case 1 box, others standard input, expected are pretty much straight forward. But I left it blank and it worked absolutely fine.

I have another query, will start a separate discussion topic for the same.
Als Antwort auf Vandana Naik

Re: Adding a new C program question

von sc kaindorf -

Here are a example for this answer: Copy and paste the my answer into the answer-textfield and add some text into the question-textfield. Also check the `checkbox` under the answer - this will generate automatically the required answer ...

#include <stdio.h>

int main(){
    
    int userInput = 0;
    int output = 0;
    
    printf("########### INPUT ###########\n");
    printf("Please insert a number: \n");
    scanf("%d", &userInput);
    
    int result = userInput % 5;
    
    switch(result){
        case 0:
            output = userInput * 2;
            break;
        case 2:
            output = userInput / 2;
            break;
        case 3:
            output = userInput + 3;
            break;
            
        default:
            output = userInput - 4;
            break;
    }
    
    
    printf("########### OUTPUT ###########\n");
    printf("The new value is: %d\n", output);
    
    return 0;
}


Insert into the testname field some Text - there is also the possibility to insert some code. In my case, there is no code required. Insert some example numbers into the Field `standard input` (e.g. 12455) and thats all.