Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / Why would a programmer intentionally code the following line into a program? (Code needed to make this a complete program intentionally left out

Why would a programmer intentionally code the following line into a program? (Code needed to make this a complete program intentionally left out

Computer Science

Why would a programmer intentionally code the following line into a program? (Code needed to make this a complete program intentionally left out.)

#define true 1
while(true)
{
// Stuff inside loop.
}

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE

Answer Preview

"Why would a programmer intentionally code the following line into a program?"
- For instance when a program needs to prompt the user for an operation (from a menu) this kind of loops are used. Or an embedded system checks periodically (in this kind of loops) all needed buffers (operations required) and acts accordingly.

Below is a complete code (also attached):

#include

#define true 1

char* s_pMenu = "Select operation:n"
"1 - Add Numbersn"
"2 - Subtract Numbersn"
"3 - Exitn";

int main()
{
int nOp ;
while(true)
{
// Stuff inside loop.
printf (s_pMenu) ;
scanf ("%d", &nOp) ;

switch (nOp)
{
case 1: printf ("Add numbers selectedn") ; break ;
case 2: printf ("Subtract numbers selectedn") ;break ;
case 3: return 0 ; break ;
default: printf ("Wrong operation. Try again!n") ; break ;
}
}

return 0;
}