Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Given a int variable named yesCount and another int variable named noCount an

ID: 3750997 • Letter: 1

Question

1. Given a int variable named yesCount and another int variable named noCount and a char variable named response, write the necessary code to read a value into into response and then carry out the following:

if the character typed in is a y or a Y then increment yesCount and print out "YES WAS RECORDED"

if the character typed in is an n or an N then increment noCount and print out "NO WAS RECORDED"

If the input is invalid just print the message "INVALID" and do nothing else.

2. HTTP is the protocol that governs communications between web servers and web clients (i.e. browsers). Part of the protocol includes a status code returned by the server to tell the browser the status of its most recent page request. Some of the codes and their meanings are listed below:

200, OK (fulfilled)

403, forbidden

404, not found

500, server error

Given an int variable status, write a switch statement that prints out the appropriate label from the above list based on status.

(IN C LANGUAGE)

Explanation / Answer

//1

#include<stdio.h>

//1

int main()

{

//variable declaration

int yesCount,noCount;

char response;

//reading input

printf("Enter number1: ");

scanf("%d",&yesCount);

printf("Enter number2: ");

scanf("%d",&noCount);

scanf("%c",&response);

//reading char

printf("Enter Y or N: ");

scanf("%c",&response);

//displaying output

if(response == 'Y' ||response =='y')

{

//incrementing variable yesCount

yesCount++;

printf("YES WAS RECORDED ");

}

else if(response == 'n' ||response =='N')

{

//incrementing variable noCount

noCount++;

printf("NO WAS RECORDED ");

}

else//if invalid input was entered

{

printf("INVALID ");

}

return 0;

}

output:

Enter number1: 5
Enter number2: 7
Enter Y or N: y
YES WAS RECORDED


Process exited normally.
Press any key to continue . . .

//2

#include<stdio.h>

int main()

{

//variable declaration

int status;

//reading input

printf("Enter status code: ");

scanf("%d",&status);

//displaying output

switch(status)

{

case 200:

printf("OK (fulfilled) ");

break;

case 403:

printf("forbidden ");

break;

case 404:

printf("not found ");

break;

case 500:

printf("server error ");

break;

default:

printf("Invalid status code ");

}

return 0;

}

output:

Enter status code: 200
OK (fulfilled)


Process exited normally.
Press any key to continue . . .