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: //...
C++ Please. Break it down barney style if possible. Instructions Create a program to keep track...
C++ Please. Break it down barney style if possible. Instructions Create a program to keep track of the statistics for a kid’s soccer team. The program will have a structure that defines what data the program will collect for each of the players. The structure will keep the following data: Players Name (string) Players Jersey Number (integer) Points scored by Player (integer) The program will have an array of 12 players (use less for testing and development, use a constant...
please code in c language and follow all instructions and sample run. Simone works for a...
please code in c language and follow all instructions and sample run. Simone works for a group that wants to register more people to vote. She knows her team can only ask a certain number of people at any given time since they have other obligations. She has asked you to create a program for her team that allows the user to type in how many people they want to ask at one time (the duration of the current program...
Please follow these instructions to complete this assignment: 1. For this assignment, you are to develop...
Please follow these instructions to complete this assignment: 1. For this assignment, you are to develop 10 questions that you would ask a management official responsible for the financial planning for the organization you have chosen to research for the week 3 paper. 2. Make sure the questions will give you insight into what the company looks for when preparing their yearly budget, fiscal planning strategies, as well as how they monitor their financial condition throughout the year and make...
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...
Make a C program that simulates time-sharing in the operating system. Please follow the instructions provided:...
Make 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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT