Computer (C)

posted by .

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;
}
}

Respond to this Question

First Name
School Subject
Your Answer

Similar Questions

  1. chemistry

    thanks DrB I got AgCl also Could you check this problem as well?
  2. bcis MS Projects

    I downloaded the trail version. got the free key code...the extension on the file is .img....what do i need to do to get the file to run?
  3. Computer Programming

    Can anyone give me a site that contains a C source code. it must be a game or something that I can copy the code. thanks
  4. Computer Programming

    can anyone give me site about programming I need a sample c or c++ source code. a program must have a description.. thanks
  5. Questions

    Okay, so I'm doing this project on careers and I need pictures. Can anyone give me ideas of what pictures would depict: - a webmaster - a web designer - a computer hardware engineer - a computer animator I've got a start, but need …
  6. Math

    Dear Readers, I am a 6th grader that recently took a math test. I got a question wrong, and I think it was because I don't know the definition to the question. Can you please tell me what an interval in mathematical terms is. Please …
  7. BUS 210

    Imagine that you are starting your own company. What will be the ethical code of your company?
  8. Computer Information

    A __________ provides the tools that a programmer uses to create software. a)compiler b) interpreter c)code d)a programming language In a way, don't all of these help a programmer to create software?
  9. Programming

    Here is the question that I need help to write the code for the following program in Visual Basic 2010. I am trying to write the code but it has a run time error. If your could helps me to write the code it would be greatly appreciated. …
  10. Computer Literary

    Which of the following is Not an example of debugging A)Looking for errors in programming code B)Fixing misspelled commands in programming code C)Solving faulty logic in programming code D)Upgrading to improve the programming code

More Similar Questions