Tuesday
July 29, 2014

Homework Help: Computer (C)

Posted by Kevin on Friday, February 1, 2013 at 10:24pm.

I need help with c programming, i need to fill in the code and I got these (need help with question 4), I run the grader and I only got question 1 right.

grader code:
gcc worksheet.c;
./a.out 0;
if [ $? -eq 0 ]
then
echo 'Question 0 Correct';
else
echo $? 'is not correct for question 0';
fi
./a.out 1;
if [ $? -gt 1 ]
then
echo 'Question 1 Correct';
else
echo $? 'is not correct for question 1';
fi
./a.out 2 9;
if [ $? -eq 9 ]
then
./a.out 2 5;
if [ $? -eq 5 ]
then
echo 'Question 2 Correct';
else
echo 'Not Correct for Question 2';
fi
else
echo 'Not Correct for Question 2';
fi
./a.out 3 9;
if [ $? -eq 0 ]
then
./a.out 3 5;
if [ $? -eq 1 ]
then
echo 'Question 3 Correct';
else
echo 'Not Correct for Question 3';
fi
else
echo 'Not Correct for Question 3';
fi
./a.out 4 1;
if [ $? -eq 5 ]
then
./a.out 4 2;
if [ $? -eq 25 ]
then
echo 'Question 4 Correct';
else
echo 'Not Correct for Question 4';
fi
else
echo 'Not Correct for Question 4';
fi
rm a.out;

homework code:
//DO NOT ALTER THE MAIN FUNCTION, THIS IS FOR GRADING.
int main(int argc, char * argv[]){
switch(argv[1][0]){
case 0:
return question0();
case 1:
return question1();
case 2:
return question2(argv[2][0]-48);
case 3:
return question3(argv[2][0]-48);
case 4:
return question4(argv[2][0]-48);
default:
return 1;
}
}

int question0(){
//return a successful exit status.
return 0;
}

int question1(){
//return your favorite positive number greater than one.
return 2;
}

int question2(int arg){
//return your input.
return arg;
}

int question3(int arg){
//if arg is greater than 5 return 0, otherwise return 1.
if (arg > 5){
return 0;}
else {
return 1;
}
}

int question4(int arg){
//return 5 multiplied by itself arg-1 times.
for (arg = 0; arg < 1; arg++){
5 * arg;
}
}

Answer this Question

First Name:
School Subject:
Answer:

Related Questions

Computer Programming - can anyone give me site about programming I need a sample...
Questions - Okay, so I'm doing this project on careers and I need pictures. Can ...
Programming - Hi. I am taking a computer programming class (C++). I need some ...
bcis MS Projects - I downloaded the trail version. got the free key code...the ...
Computer Information - A __________ provides the tools that a programmer uses to...
Question - Okay, so I'm doing this project on careers and I need to find out the...
Computers - what files do i need for windows 1998 and 2000? What do you mean ...
programming - I keep getting a 'Code 0; Permission Denied' error, while trying ...
computer science - I need help with c++ on the codeblocks. when i run the ...
Programming Logic - I need to create a flowchart/psuedocode for a dice game that...

Search
Members