Question

Write a script that inputs integers (one at a time) and passes them one at a...

Write a script that inputs integers (one at a time) and passes them one at a time to function isEven. which uses the modulus operator to determine whether an integer is even. The function should take an integer argument and return true if the integer is even and false otherwise. Use sentinel-controlled looping and a prompt dialog.

notepad++

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
using namespace std;

bool isEven(int num) {
    return num % 2 == 0;
}

int main() {
    int num;
    do {
        cout << "Enter a number(-99 to exit): ";
        cin >> num;
        if (num != -99) {
            if (isEven(num)) {
                cout << num << " is even." << endl;
            } else {
                cout << num << " is odd." << endl;
            }
        }
    } while (num != -99);
    return 0;
}

Add a comment
Know the answer?
Add Answer to:
Write a script that inputs integers (one at a time) and passes them one at a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • IN HTML Programming 1. Write a script that inputs integers (one at a time) and passes...

    IN HTML Programming 1. Write a script that inputs integers (one at a time) and passes them one at a time to function isEven, which uses the modulus operator to determine whether an integer is even. The function should take an integer argument and return true if the integer is even and false otherwise. Use sentinel-controlled looping and a prompt dialog.

  • Write a function called isEven() that uses the remainder (modulus) operator (%) to determine when an...

    Write a function called isEven() that uses the remainder (modulus) operator (%) to determine when an integer is even. The function should take an integer argument called myNumber passed from within the for loop and return true if the integer is even and false otherwise. Your program should determine what numbers are even and odd from 1 to 20 using the isEven() function. Your counter variable in the for loop should be called num.

  • Write a script, shuffle.sh which generate. Unique integers and prints them out sorted in ascending order,...

    Write a script, shuffle.sh which generate. Unique integers and prints them out sorted in ascending order, and then shuffled. The count of the integers is given as a command-line argument. The shell variable RANDOM generates a random integer upon evaluation. In other words echo $ random prints a random integer. You may assume that the command line argument is a valid positive integer. Use only shell constructs and the array structure. In other words, don’t use commands such as sort,...

  • This is in Java. Write the application, TheSentinel  to read a set of integers. Stop reading input...

    This is in Java. Write the application, TheSentinel  to read a set of integers. Stop reading input when a non-integer is read. Use this exact prompt: System.out.print("Enter an integer or Q to quit: "); Note: you will actually quit on any non-integer. Do the following things: Find and print the sum of all the even numbers Find and print the smallest of the inputs Determine if the number 7 is in the input. If 7 is in the inputs, print "7...

  • Write a bash script that accepts one command line argument 'a' which is an integer between...

    Write a bash script that accepts one command line argument 'a' which is an integer between 1 and 50 inclusive. It should output a list of integers from 'a' and ending with '1' according to the following iteration rule. ( fx = x/2 if x is even; fx=3x+1 if x is odd )

  • Question is two parts In R(Programming language). Define and write a function which takes one number...

    Question is two parts In R(Programming language). Define and write a function which takes one number as input and detects whether the number is even. Return TRUE if it is even, and FALSE otherwise. You need to first detect if the input is an integer; if not, return NA. Note 1: TRUE and FALSE are logical values, not strings! Note 2: No need to get user input from the console. Test your function using your_function_name(1), your_function_name(2), and your_function_name(1.5). Hint: What...

  • Write a bash script that accepts one command line argument 'a' which is an integer between 1 and 50 inclusive. I...

    Write a bash script that accepts one command line argument 'a' which is an integer between 1 and 50 inclusive. It should output a list of integers from 'a' and ending with '1' according to the following iteration rule. ( fx = x/2 if x is even; fx=3x+1 if x is odd )

  • write a program that asks the user to enter two integers one at a time if...

    write a program that asks the user to enter two integers one at a time if the first value is not an integer then do not ask for a second then display both values otherwise print error message stating which value entered was not an integer python

  • MATLAB homework assignment (HW6), but this time using a "vectorized" approach. Write a script that prompts...

    MATLAB homework assignment (HW6), but this time using a "vectorized" approach. Write a script that prompts the user for N integers (set N-6), one at a time, using a while loop. Error-check to ensure that each number entered is an integer, displaying an error message if it is not. If it is an integer, store it in an array variable nums. Continue prompting until N integers have been successfully entered. (You may copy and paste your code from the previous...

  • Please help, using Python Write a Python function sum_of_4th_powers, which accepts one argument. You can assume...

    Please help, using Python Write a Python function sum_of_4th_powers, which accepts one argument. You can assume that the function is only called with an integer n as argument, i.e., no need to worry about invalid inputs. If the argument n can be written as a sum n=a4+b4+c4 with all of a,b,c being non-zero, your function should return such a decomposition. Otherwise your function must return False. For example: sum_of_4th_powers(5) must return False, sum_of_4th_powers(18) could return (1,1,2). *Please go step by...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT