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
What classes should I take in high-school for majoring in computer science?
Gala2k [10]

Answer:

Computer science are the disciplines that study information, computing and the applications or ecosystems where they are developed. It is a science that comes from applied mathematics and has 3 branches that are quite well known. On the one hand we have software engineering, secondly theory as such (primary study of algorithms and data, etc.) and finally the application of the amalgam of the first two, which end up resulting in disciplines such as big data, cybersecurity or computer security, machine learning, artificial intelligence, etc. However, we are talking about a very broad science with various branches of work. Technological advances that have improved the scope of education, now allow us to develop in specific skills and computer science is one of the macro careers that have benefited the most thanks to the diversity of subjects it encompasses. This is where the on-demand courses available on the edX platform come in. Computer scientists are in one of the best times for their career advancement. We invite you to be part of the technological development and information and computing technologies through online courses.

Explanation:

6 0
3 years ago
Video Fundamentals
Tresset [83]

Answer:

1) a link, original, a pointer.

2) The media browser can help you by providing the very quick accessibility to all of your assets like iTunes songs, your movies in the movie folder, and this makes your file browsing experience simple while you edit the files.

You can leave the browser open as well as docked quite in the same manner as the other panel.

3) You need to display the Voice-over Record button. Now select your track in the timeline where you want to add the voice-over.

Now you need to go to the Timeline, and click on the Settings button, and finally select the Customize Audio Header.

Now you will see the Button Editor dialog box appearing, and now you need to drag and drop the microphone button to the required audio track, and finally, you need to click on OK.

4) While you are importing the audio or video to the Premiere Pro, it computes versions of such files, which it can readily use for quicker performance. And these are being termed as the Media cache files. And they are being saved in the Media cache files folder.

Explanation:

Please check the answer.

6 0
4 years ago
In order for a sort to work, which of the following is required?
nydimaria [60]
Can u plz give me a picture
3 0
3 years ago
Production cost can be reduced using technology. Explain
Black_prince [1.1K]

Explanation:

By reducing the time the use on unnecessary tasks. And you would be able to operate on using your time on beneficial tasks

3 0
3 years ago
What is the faster way for browsers to obtain the revocation status of a digital certificate attached to a Web site?
Lyrx [107]

Answer:

The fastest way to obtain the revocation status of digital certificate of the website is by using Online certificate Status Protocol (OSCP).

Explanation:

Online certificate status protocol is the protocol that help user to check and verify the digital certificate revocation status. This protocol is linked with the digital certificate issuance authority. Whenever someone want to verify the status of the digital certificate that is attached to access the website. The website administrator can send the request to OSCP handler to ensure the status of the certificate. The OSCP handler is connected through certificate issuance authority, send the detail to verify the status. After verifying the status, OSCP handler respond as certificate is valid or revoked to the concerned user.

5 0
4 years ago
Other questions:
  • How can i save a word 2016 document as a word 2016 document?
    6·1 answer
  • Prove that for every nfa with an arbitrary number of final states there is an equivalent nfa with only one final state. Can we m
    8·1 answer
  • Software that interprets commands from the keyboard and mouse is also known as the
    8·1 answer
  • Match each invention with its effects on the age of exploration.
    6·2 answers
  • Servlet session and JSP session have differentabilities.<br>? True<br><br>? False
    15·1 answer
  • Henry must choose which type of smart speaker to use in his home. He asked you to help him decide which one will best suit his n
    8·1 answer
  • Design an Application called Student Course Management create interface called Student Course add an abstract method called ad C
    10·1 answer
  • Debugging 2.17.3: Debug: The Two Towers Code Hs
    15·1 answer
  • Make and run a Python program which:
    13·1 answer
  • How do i unblock a website on a school computer if a school blocks it?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!