Question

In: Computer Science

C++ Follow Instructions Please By placing a break in the IIF statement you are using it...

C++

Follow Instructions Please

By placing a break in the IIF statement you are using it to force an exit from the WHILE loop. The break statement is only allowed with the SELECT/CASE statement. Also, don't use one structure to force an exit from another. Use the logic from the WHILE loop to end by removing the IF with the break

#include <iostream>
using namespace std;


bool IsMultiple(int,int);

int main()
{
        char choice;
        int n1,n2;
        bool result;
        int test = 0;
        cout << "Do You Want to Play? (Y/N)" << endl;
        choice = cin.get();
        while(choice == 'Y')
        {
                cout << "Test" << ++test << endl;
                cout << "X: ";
                cin >> n2;
                cout << "Y: ";
                cin >> n1;
                
                result = IsMultiple(n2,n1);
                cout << result << endl;
                
                cout << "Do You Want to Play Again" << endl;
                cin >> choice;
                if(choice == 'N')
                {
                        break;
                }       
        }       
}
bool IsMultiple(int x, int y)
{
        if(x % y == 0)
        {
                cout << "Number " << x << " is divisible by " << y << endl;
                return true;
        }
        else
        {
                cout << "Number " << x << " is not divisible by " << y << endl;
                return false;
        }
}

Solutions

Expert Solution

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

#include <iostream>
using namespace std;


bool IsMultiple(int,int);

int main()
{
char choice;
int n1,n2;
bool result;
int test = 0;
cout << "Do You Want to Play? (Y/N)" << endl;
choice = cin.get();
while(choice == 'Y')
{
cout << "Test" << ++test << endl;
cout << "X: ";
cin >> n2;
cout << "Y: ";
cin >> n1;

result = IsMultiple(n2,n1);
cout << result << endl;

cout << "Do You Want to Play Again" << endl;
cin >> choice;
while(choice!='Y'&&choice!='N')
{
cout<<"Invalid choice!!"<<endl;

cout << "Do You Want to Play Again" << endl;
cin >> choice;
}
}
return 0;
  
}
bool IsMultiple(int x, int y)
{
if(x % y == 0)
{
cout << "Number " << x << " is divisible by " << y << endl;
return true;
}
else
{
cout << "Number " << x << " is not divisible by " << y << endl;
return false;
}
}

Kindly revert for any queries

Thanks.


Related Solutions

Please follow the instructions and solve it by C++. Thank you! What to Submit Submit the...
Please follow the instructions and solve it by C++. Thank you! What to Submit Submit the following: 1) Your .cpp file of the solution. 2) For what n value (approximately) does your computer stop producing output? Why is this? Enter your answer in the 'Comments' field when you submit the file.   So far in our study of recursion we identified a few common recursive number sequences, such as the Fibonacci numbers. Number sequences like this are not recursive algorithms themselves...
in c++ please follow instructions and fix the errors and please make a comment next to...
in c++ please follow instructions and fix the errors and please make a comment next to each code error you fix. Below are 25 code fragments, inserted into a try catch block. Each line has zero or more errors. Your task is to find and remove all errors in each fragment. Do not fix problems by simply deleting a statement; repair the problems by changing, adding, or deleting a few characters. There may be different ways to fix them You...
Please follow the instructions and solve it by c++ Close the project and create a new...
Please follow the instructions and solve it by c++ Close the project and create a new one called 'Lab0-Part3' with the same options as in the previous step. Write a C++ program that does the following: Creates a 100-element array, either statically or dynamically Fills the array with random integers between 1 and 100 inclusive Then, creates two more 100-element arrays, one holding odd values and the other holding even values. Prints both of the new arrays to the console.
Please complete the following code in C using the comments as instructions. Further instructions are below...
Please complete the following code in C using the comments as instructions. Further instructions are below the code. challenge.c // goal: print the environment variables to the file "env.txt", one per line // (If envp is NULL, the file should be empty, opening in write mode will do that.) // example: // inputs: // envp/environ = {"E1=2","E2=7",NULL} // outputs: // env.txt as a string would be "E1=2\nE2=7\n" // example: // inputs: // envp/environ = {NULL} or NULL // outputs: //...
Create a C program that simulates time-sharing in the operating system. Please follow the instructions provided:...
Create a C program that simulates time-sharing in the operating system. Please follow the instructions provided: a) Use a circular queue. b) It is required that the process be inputted by the user. The user must input the process name and the duration in seconds, and for this simulation let the user input 5 processes. c) As this requires process name and duration, use an array of structures. d) To simulate time-sharing, following the algorithm presented below: d.1) Use the...
Please follow these instructions carefully. The more accurately you describe everything you eat or drink, the...
Please follow these instructions carefully. The more accurately you describe everything you eat or drink, the more helpful the record will be to us in our research. 1. At the top of each page, fill in the day of the week, and the date. 2. Write down everything you eat or drink, including water, and all vitamin/mineral supplements taken for the 3-day period. Don’t forget to include snacking or food eaten while preparing a meal. Every bite counts! 3. For...
please follow the instructions and ASAP. It is a project work. we need to write a...
please follow the instructions and ASAP. It is a project work. we need to write a report about to ::: find a real-life corrosion problem that has not been solved, conduct a thorough investigation as to the cause(s) and type(s) of corrosion, and, finally, propose possible solutions for the problem, indicating which of the solutions is best and why. Submit a report that addresses these issues.
Please Read Carefully Before start answering this question. Please follow the instructions. This Question is from...
Please Read Carefully Before start answering this question. Please follow the instructions. This Question is from 'BSBFIM501 Manage budgets and financial plans' course. There are no parts missing for this Question; guaranteed!. This is the original Screenshot direct from the question. Therefore, there are nothing any further information can be provided. Thanks for your understanding and Cooperation. Please answer the following questions from the topics discussed for Prepare, implement, monitor and modify contingency plans: 1.a. Explain the process of preparing...
Please use Minitab and follow instructions given with the problem A contractor has recorded the number...
Please use Minitab and follow instructions given with the problem A contractor has recorded the number of jobs performed in the last seven months. Last year’s performance evaluation score For each of the following methods, develop a forecast for the number of jobs for the 8th month. A three-period moving average Exponential smoothing (use Minitab default smoothing parameters) A linear trend equation Using the mean squared difference (MSD), explain which of the methods you believe results in the best forecast...
QUESTION 9 Instructions: Please read the passage below, then answer the questions that follow. ------------------------------------------------------------------------------------------------ Zoey...
QUESTION 9 Instructions: Please read the passage below, then answer the questions that follow. ------------------------------------------------------------------------------------------------ Zoey wanted to buy a new car but was having difficulty deciding what kind of car to buy. She was feeling anxious and wanted to make a decision soon. It was a very cold day in January, and she was preparing for a long day; so Zoey decided to wear her glasses, a long pea coat, and her work satchel. Zoey had conducted some research...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT