Question

In: Computer Science

c++ Write a program that will ask the user for three pairs of integer values. The...

c++

Write a program that will ask the user for three pairs of integer values. The program will then display whether the first number of the pair is multiple of the second.

The actual work of making the determination will be performed by a function called IsMultiple that takes two integer arguments (say, x and y). The function will return a Boolean result of whether x is a multiple of y.

Solutions

Expert Solution

In this C++ program,

- In main, we are prompting the user to enter pairs of integer values, then
- We are calling the function isMultiple which will take 2 arguments and return a boolean value.This function will check if the first number of the pair is multiple of the second then returns true if satisfied else return false.
- Again back in main, we are storing the result, and printing whether the first number is a multiple of the second number or not,

(I believe that I made the code simple and understandable. If you still have any query, Feel free to drop me a comment)

Code:

#include <iostream>
using namespace std;

//This function will take 2 arguments and return a boolean value
bool isMultiple(int x,int y)
{
if(x%y==0)
return true;
else
return false;
}

int main()
{
int a,b;//Declared this variables to store integer pairs

//Looping to accept 3 pairs of integer values
for(int i=0;i<3;i++)
{
//Prompting and reading the values from the user
cout<<"Enter the Integer pair "<<i+1<<": ";
cin>>a>>b;
//Calling the function and storing the result
bool result=isMultiple(a,b);
//Printing whether it is a muliple or not
if(result)
cout<<a<<" is a muliple of "<<b;
else
cout<<a<<" is not a muliple of "<<b;
cout<<endl;
}
return 0;
}



Output:


Hope this Helps!!!
Please upvote as well, If you got the answer?
If not please comment, I will Help you with that...


Related Solutions

• Write a C++ program that asks the user to input two integer values, then calls...
• Write a C++ program that asks the user to input two integer values, then calls a void function "swap" to swap the values for the first and second variable. • As we mentioned before, in order to swap the valors of two variables, one can use the following: temp= variable1; variable1 = variable2; variable2 = temp; • Display the two variables before you call swap and after you call that function. Comment in code would be greatly appreciated to...
Write a program that does the following. It will ask the user to enter an integer...
Write a program that does the following. It will ask the user to enter an integer larger than 1, and the if entered integer is not larger than 1, it keeps prompting the user. After the user enters a valid integer, the program prints all the prime factors of the integer (including the repeated factors). For example, if the entered integer is 24, the program prints: 2 2 2 3 Run your program with the test cases where the entered...
Write a mips assembly code program that ask the user to enter an integer value, and...
Write a mips assembly code program that ask the user to enter an integer value, and then print the result of doubling that number.
(8 marks) Write a program to ask user to enter an integer that represents the number...
Write a program to ask user to enter an integer that represents the number of elements, then generate an ArrayList containing elements which are all random integers in range [75, 144] , and finally display index and value of each element. REQUIREMENTS The user input is always correct (input verification is not required). Your code must use ArrayList. Your program must use only printf(…) statements to adjust the alignment of your output. Your code must display the index in descending...
Write a program to find the prime numbers IN JAVA Ask user to input the integer...
Write a program to find the prime numbers IN JAVA Ask user to input the integer number test the number whether it is a prime number or not Then, print “true” or “false” depending on whether the number is prime or isn’t. Hint: number is prime when is has exactly 2 factors: one and itself. By this definition, number 1 is a special case and is NOT a prime. Use idea of user input, cumulative sum, and loop to solve...
Write a Java program that prompts the user to enter a list of integer values and...
Write a Java program that prompts the user to enter a list of integer values and displays whether the list is sorted in increasing order or not. Here is a sample run. Note that the first number in the input indicates the number of the elements in the list. <Output> Enter list: 8 101516619111 The list is not sorted <End Output <Output> Enter list: 10 11344579 11 21 The list is already sorted <End Output Create a complete class for...
Write a C# program that prompts the user to enter in three values. The first indicates...
Write a C# program that prompts the user to enter in three values. The first indicates a starting (whole number positive) value, the second an ending value and the third an increase value. output a table of squares and square roots, every increase value from the start to the end value. For instance if the values were: start 3, end 20, and increase 4. the table would consist of 3,7,11,15,19 and their squares and square roots. Please include all code...
Write a C++ program that asks the user for the values of three resistances. We suppose...
Write a C++ program that asks the user for the values of three resistances. We suppose that the user will not enter a negative value. The program then asks the user whether he has a series or parallel montage. The user will answer with S or s for series and P and p for parallel. (If the user enters a wrong answer, he will see a message on the screen alerting him, and the program will end.) Finally, the program...
Write a C program that allows: Three integer values to be entered (read) from the keyboard,...
Write a C program that allows: Three integer values to be entered (read) from the keyboard, Display the sum of the three values on the computer screen as follows: The integers that you have entered are: a b c The sum of a , b & c is ______ Thank you! C Code: Output screen:
Write a Java program that will ask the user for his/her salary (numerical integer salary) and...
Write a Java program that will ask the user for his/her salary (numerical integer salary) and then convert this numerical salary into income class. The following is a guideline to the income class used. The numeric range within parenthesis maps to the preceding class. If the user gave you a number greater than 700,000 or less than 10,000, you should print a message that the input is invalid. In this code, DO NOT USE && OPERATOR. You should use if-else....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT