168k views
0 votes
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.

User Implmentor
by
7.5k points

1 Answer

3 votes

Answer:

A switch statement is a set of different outputs depending on the number of criteria asked to follow.

Given an integer number as a variable status, the algorithm would state as the following:

int num

switch (num) {

case 200:

printf(OK);

break;

case 403:

printf(Fobidden);

break;

case 404:

printf(Not Found);

break;

case 500:

printf(Server Error);

break;

default:

printf(Not a proper value);

break;

}

Depends on the value of hte variable "num", it will fall in one of the options above. If the variable has a different value that doesn't fit in any of the options above, it will prompt the default message.

User Ovk
by
7.9k points