Question: write the code C programming if you would kindly. Ternary if you would. I have a new question so look at that for further reference

write the code C programming if you would kindly. Ternary if you would. I have a new question so look at that for further reference about an hour ago.

https://www.chegg.com/homework-help/questions-and-answers/write-code-c-programming-would-kindly-ternary-would-need-submit-second-code-guessing-game--q68824118

You need to submit the second code with Guessing Game based on Ternary Search.

Ternary Search presupposes that during the game the search space is reduced by 2/3 rather than cut by half. For example, let us suppose that low=0 and high is 90. We define two markers whose values would be

m1=30

m2=60

We will ask to press a certain key if

target number is equal to m1 or m2

target number is greater than m2

target number smaller than m2

New search space would contain only 30 numbers. Continue accordingly.

so build a trinomial that checks all these marks

#include "pch.h"

#include

int main()

{

int high, low, middle;

char input;

printf("Please enter low bound ");

scanf_s("%d", &low);

printf("Please enter high bound ");

scanf_s("%d", &high);

printf("Your number has to be between %d and %d ", low, high);

while (low <= high)

{

middle = ?;

printf(" Please, press E or e if your number is equal to %d ", middle);

printf(" Please, press G or g if your number is greater than %d ", middle);

printf(" Please, press S or s if your number is smaller than %d ", middle);

scanf_s(" %c", &input);

if (input == 'E' || input == 'e')

{

printf("Done! I've guessed your number ");

low = ?; // MAKE LOOP CONDITION FALSE

}

else

{

if (input == 'G' || input == 'g')

low = ?;

else

high = ?;

}

}

printf(" Thanks for playing! ");

}

then alter the first line of code to meet all these requirements

Please enter low bound

20

Please enter high bound

180

Your number has to be between 20 and 180

I will guess your number m aximum with 8 questions

Question 1

Please, press E or e if your number is equal to 100

Please, press G or g if your number is greater than 100

Please, press S or s if your number is smaller than 100

g

Question 2

Please, press E or e if your number is equal to 140

Please, press G or g if your number is greater than 140

Please, press S or s if your number is smaller than 140

s

Question 3

Please, press E or e if your number is equal to 120

Please, press G or g if your number is greater than 120

Please, press S or s if your number is smaller than 120

e

Done! I've guessed your number with 3 questions

Thanks for playing!

Here's what I have written for the ternary question

#include "pch.h"

#include

int main()

{

int high, low, one, two;

char input;

printf("Please enter low bound ");

scanf_s("%d", &low);

printf("Please enter high bound ");

scanf_s("%d", &high);

printf("Your number has to be between %d and %d ", low, high);

while (low <= high)

{

one = (high + low) / 3;

printf(" Please, press E or e if your number is equal to %d ", one);

printf(" Please, press G or g if your number is greater than %d ", one);

printf(" Please, press S or s if your number is smaller than %d ", one);

scanf_s(" %c", &input);

two = ((high + low) / 3) * 2;

printf(" Please, press E or e if your number is equal to %d ", two);

printf(" Please, press G or g if your number is greater than %d ", two);

printf(" Please, press S or s if your number is smaller than %d ", two);

scanf_s(" %c", &input);

if (input == 'E' || input == 'e')

{

printf("Done! The program has guessed your number ");

low = high; // MAKE LOOP CONDITION FALSE

}

else

{

if (input == 'G' || input == 'g')

low = one + 1;

else

high = one - 1;

}

{

if (input == 'G' || input == 'g')

low= two + 1

else= two-1

}

}

printf(" Thanks for playing! ");

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!