1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
TiliK225 [7]
3 years ago
8

Can someone help with this assignment for C++? We were just introduced to loops, specifically while loop, do-while loop, for loo

p, and nested loops.
Write a program that reads a sequence of integers and prints the following:
The number of odd and even numbers of inputs
Use a sentinel value to signal the end of inputs. If the sentinel value is the first you enter, give a message "NO input is entered!".
Input Validation: Do not accept a negative number.
Computers and Technology
1 answer:
Studentka2010 [4]3 years ago
3 0

Answer:

  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.    int value;
  6.    int oddCount = 0;
  7.    int evenCount = 0;
  8.    
  9.    cout<<"Input a positive number: ";
  10.    cin>> value;
  11.    
  12.    if(value == -1){
  13.        cout<<"NO input is entered!";
  14.        return 0;
  15.    }
  16.    
  17.    if(value < -1) {
  18.          cout<<"The input number must be positive";
  19.          return 0;
  20.    }
  21.    
  22.    while(value != -1){
  23.        
  24.        if(value % 2 == 0){
  25.            evenCount++;
  26.        }else{
  27.            oddCount++;
  28.        }
  29.        cout<<"Input a positive number: ";
  30.        cin>>value;
  31.        if(value < -1){
  32.              cout<<"Wrong input number\n";
  33.              return 0;
  34.        }
  35.    }
  36.    
  37.    cout<<"Number of odd number: "<< oddCount<<"\n";
  38.    cout<<"Number of even number: "<< evenCount;
  39.  
  40.    return 0;
  41. }

Explanation:

Firstly, create three variables, value, oddCount and evenCount (Line 7-9). The value variable is to hold the input number from user (Line 11 -12). oddCount and evenCount are to track the number of occurrence of even and odd number of the user input (Line 21-25).

The sentinel value here is -1 and therefore if user enter -1 as first input, the message "NO input is entered!" will be displayed. (Line 14).

If user input a negative value other than -1 , display the alert message to user and terminate the program (Line 19-22).

We check if the value modulus by two is zero, this means it is an even number and then increment evenCount by one (Line 26-27). Otherwise increment oddCount by one (Line 28-29).  

After that prompt the user to input another number again and repeat the loop (Line 31-36). So long as the user don't enter -1, the while loop will just keep running.

At last, print the number of odd and even number (Line 40-41).

You might be interested in
Why is storage and important part of the computing process? It must be atleast five sentences.
worty [1.4K]

Your computer needs storage because the processor needs a place to perform its magic — a scratchpad for mad doodles, if you will. All computers need storage. ... Memory is where the processor does its work, where programs run, and where information is stored while it's being worked on.

And why five sentences?

3 0
3 years ago
Where is permanent data in the computer stored? Whenever Jim starts his laptop, he sees some commands and numbers appearing on h
Wittaler [7]

the operating system ithink

4 0
4 years ago
How many bits can a memory chip with the below configuration support? For full credit, show how you got the answer.
tatiyna

Answer:

Total Memory= 4 KB = 4096 bytes = 32768 bits

Explanation:

<em><u>1. Data lines are 8 From D0 to D7</u></em>

so

Total memory at single address locations is 8 bits.

<em><u>2. Address lines are 12 (A0 to A11)</u></em>

There are 12 address lines but 3 out 12 are for selction of chip or memory bank.

so only 9 pins are there to address the locations on one chip.

Total No. of address locations on single chip = 2^9 = 512 locations

as 1 location is 1 byte so total memory of single chip is 512 bytes.

<u><em>3. Total Memory Bank </em></u>

There are total 3 selection pins for memory bank.

so

Total chips = 2^3 = 8.

<em><u>4. Total Memory </u></em>

Total size of 1 chip = 512 bytes

Total size of 8 chip = 8x512 bytes = 4096 bytes = 4096/1024 kb = 4 kb

<em>So total memory of system is 4 Kb = 4096 bytes = 32768 bits</em>

5 0
3 years ago
Provide an example of a question that could NOT be answered with a binary message. Explain why this is the case, making referenc
solong [7]
This is a question with a much simpler answer given its open ended ness - a representation merely means, given binary data, we can determine what 'thing' that binary data corresponds to.

<span>That makes the question unanswerable, because words can all be represented in binary data, and the question cannot be answered without those. Thus, all answers we can convey have a binary representation of some form (that form being the translation of the words we used to communicate the answer into binary data).</span>
7 0
4 years ago
What is bugtraq?
beks73 [17]

Answer:

The answer would be (C) An industry mailing list provided by Symantec that reports new vulnerabilities as they are discovered.

I hope this helped!

3 0
3 years ago
Read 2 more answers
Other questions:
  • Write a function so that the main() code below can be replaced by the simpler code that calls function MphAndMinutesToMiles(). O
    5·1 answer
  • The merge process involves which two types of files?
    5·1 answer
  • What statement needs to be included below to retrieve all rows from the Invoices table with InvoiceTotal greater than 100?
    9·1 answer
  • How can utility poles be eliminated as roadside hazards
    9·1 answer
  • HELP WILL GIVE BRAINLIEST
    5·1 answer
  • Lester has to create an app that can support offline data and rich media content such as audio and video. In which programming l
    15·1 answer
  • How do I convert years to days on Python. For example, if I were to enter 3 years it should output "You are 1095 days old".
    5·1 answer
  • Describe in detail what each step would look like if you ran into a software error.
    7·1 answer
  • Question 1 (1 point)
    13·1 answer
  • Convert Octal 623, to Decimal number ​
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!