Write a for loop that counts only the odd numbers

Assignment Help C/C++ Programming
Reference no: EM131207294

Here are two examples:

if(counter==7)

continue;

if(counter==7)

break;

1. Write a for loop that counts only the odd numbers out of the first five numbers entered from the keyboard, but does not count (skips) the number 7. Use the keyword continue to skip 7 inside the loop

2. Write the same program above, but exit the for loop using break if the number 7 is entered.

#include <iostream>

using namespace std;

intmain() {

                int sum = 0;

                intnum[5];

                for (int counter = 0; counter < 5; counter++) {

                                cout<< "Enter a Number: ";

                                cin>>num[counter];

                                if (num[counter] % 2 != 0)

           sum = sum + num[counter];

                }

                cout<< "Sum of Odd Numbers is: " << sum <<endl;

                system("pause");

                return 0;

}

Reference no: EM131207294

Questions Cloud

Explain role of us supreme court in criminal justice policy : Examine potential issues that must be evaluated in the future by the U.S. Supreme Court that will further shape criminal justice policy (e.g., you could discuss how advances in technology such as surveillance, computer analysis, drones, police equ..
Advertisement elasticity of demand for good : The price elasticity of good Y is -1.46. The advertisement elasticity of demand for good Y is 3.53. And these two elasticities are assumed to remain constant over the planned price and advertisiment changes.
Undergoes a thermodynamic cycle : A certain fixed mass system involves R-22 and undergoes a thermodynamic cycle. The cycle involves exactly two processes: A and B. Process A starts at state 1 and ends at state 2, and is the initial process of the cycle. The following are also give..
Find type and impedance in ohms of series circuit elements : Find the type and impedance in ohms of the series circuit elements that must be in the closed container of given figure for the indicated voltages and currents to exist at the input terminals.
Write a for loop that counts only the odd numbers : Write a for loop that counts only the odd numbers out of the first five numbers entered from the keyboard, but does not count (skips) the number 7. Use the keyword continue to skip 7 inside the loop
Formula for the endogenous variables : Determine a successful separation into exogenous and endogenous variables, and c) find an explicit formula for the endogenous variables in terms of the exogenous ones:
Explain the accepted identification procedures : Explain the accepted identification procedures, prepare a brief for excluding pre-trial identifications, and brief the Biggers case to demonstrate the factors the Courts will consider as a part of their ruling on whether a proper identification pr..
Consistent with the claim : Solomon company prints baseball cards, The company claims that 40% of the cards are rookies, 70% veterans and 10% are all stars, Suppose a random sample of 100cards has 50 rookies, 48 veterans and 8 all stars. is this consistent with the claim? Us..
How is biologos different from intelligent design : How is BioLogos different from Evolutionism, Intelligent Design, and Creationism? Why should all citizens and scientists embrace religion and all religion embrace science?

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Write a program that prompts the lowest temperature

Write a program that prompts the user for the lowest and highest Fahrenheit temperature wanted in the table, and also prompts the user for the desired step size between rows of the table.

  Write cpp program that is menu-driven that allows for choice

Write a C++ program that is menu-driven that allows for the following menu choices: Load an exam: Loading an exam should prompt the user for an exam file.

  How will you do the shrink operation

How will you do the shrink operation and how will you do the expand operation -

  Expand the "currency conversion" program to include a menu

Expand the "Currency Conversion" program to include a menu that allows the user to choose which currency he/she wishes to display in its equivalency to the US dollar. - Correctly use at least 1 function or subroutine

  Create a function that will accept a scalar value

Create a function that will accept a scalar value for the radius of the cylinder and end caps and will accept an array for the height of the cylinder.

  Create and prepare a disk file for records containing struct

Store the account records in the file using the same hashing/rehashing technique used for storing them in an array of structures.

  Write function to count the number of sentences

Count the number of words as well as the sentences and return and average the number of words per sentence.

  Creating a malware analysis environment

1. What are two items to consider when creating a malware analysis environment?

  Analyze the nature and purpose of budgeting

Analyze the nature and purpose of budgeting, the stages involved in the preparation of budgets, identifying separately the roles of managers and the budget committee. *Please answer it according to the marks and make it at least 750 words and above.

  Relationship between obesity and food consumption

Researcher states that there is relationship between obesity and food consumption. Obesity is the condition of excess body fat and it can get diabetes, heart disease, high blood pressure and also fatal. People in the US getting obese because of the l..

  Search the maximum number from a list of numbers

Write a function to search the maximum number from a list of numbers:

  Describe what an attribute or data member of a class

Analyze a basic set of requirements for a problem - Describe what an attribute or data member of a class - Distinguish between pass-by-value and pass-by-reference

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd