37.0k views
3 votes
Write an application that asks a user to type an even number or the sentinel value 999 to stop. When the user types an even number, display the message "Good job!" and then ask for another input. When the user types an odd number, display an error message, "x is not an even number", and then ask for another input. When the user types the sentinel value 999, end the program

2 Answers

4 votes

Answer:

int value;

while(1){

scanf("%d\\", &value);

if(value == 999)

break;

if(value%2 == 0)

printf("Good job");

else if(value%2 == 1)

printf("%d is not an even number", value);

}

Step-by-step explanation:

I am going to write a C code for this.

The while(1) runs until the break command. So

int value;

while(1){

scanf("%d\\", &value);

if(value == 999)

break;

if(value%2 == 0)

printf("Good job");

else if(value%2 == 1)

printf("%d is not an even number", value);

}

User Candre
by
5.6k points
2 votes

Answer:

do{

std::cout << "input an even number: ";

std::cin >> n;

even=n%2;

if (even==0)

std::cout << "Good job!\\";

else

std::cout << n <<" is not an even number\\";

}while(n!=999);

Step-by-step explanation:

#include <iostream>

#include <string>

int main()

{ int n=0,even;

do{

std::cout << "input an even number: "; //print on screen to input the number

std::cin >> n; //put that value on n variable

even=n%2;

if (even==0) //if even is zero the number is even

std::cout << "Good job!\\";

else //if even is not zero the number is odd

std::cout << n <<" is not an even number\\";

}while(n!=999); // we will repeat the proccess while n is diffrente from 999

}

User Lusi
by
4.6k points