Youre a professor for CS 1 at the local community college te

You\'re a professor for CS 1 at the local community college teaching C++ and one of your comes up to you about a program they are writing. They want to write a game that will check if the wants to continue to play a guessing game. They\'ve written the conditional code part below. Is it correct? Yes or no? If no, strikeout the code and rewrite it to the right of the statements. string user Value; cout

Solution

Solution:

Q25.

The changes that can be made are a follows:

bool userValue;                          // to hold true or false value bool datatype is the most appropriate one

cout<<\"Enter true or false\" <<endl;

cin>>userValue;

int userNum = 0;

if(userValue== true)

{

cout<<\"Enter a number between one and ten\"<< endl;

cin>> userNum;

}

else

{

cout<<\" Game over\";

}

Q26:

The conditional expression for the if-else statement is given below:

(x<5) ? std::cout<< (x=-y); : std::cout<< (y = x);      

the above statement first checks the condition, if it is true then x variable is asssgined with the value -y and get printed otherwise, variable y is assigned with value x and gets printed.

 You\'re a professor for CS 1 at the local community college teaching C++ and one of your comes up to you about a program they are writing. They want to write a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site