Sum of all odd numbers between a and b

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

Question: The sum of all odd numbers between a and b (inclusive). Where a and b are read in by the user.

Can you find the error in this code and if need to change it then please change and provide the desired code. Thanks!

int main()

{

int a, b , sum;

cout << "Enter the first integer: ";

cin >> a;

cout << "Enter the second integer: ";

cin >> b;

  for (a, b; ; a++,b++)

   if (a % 2 == 1 && b % 2 == 1 )

sum = a + b;

cout << sum << endl;

getch ();

}

Add comments in code section. Code this program in C++ programming.

Reference no: EM13696579

Questions Cloud

Write a marie program : Write a Marie program - Given a numbers in memory, labelled V, reverse its sign - You can halt your program once the Result is determined.
Different types of digital modulation schemes : How can we compare the performance of two or more different types of digital modulation schemes?
Creates an object of type fahrenheit : Creates an object of type Fahrenheit and an object of type Celsius - Accepts a single argument from the command line
Should the cio or cto report to the company president : Contact at least three people at your school or a nearby company who use information systems. List the systems, the position titles of the users, and the business functions that the systems support.
Sum of all odd numbers between a and b : The sum of all odd numbers between a and b (inclusive). Where a and b are read in by the user - Can you find the error in this code.
Represent 99 and -99 in 2s complement format : what are the largest(positive) and smallest (negative) integers a word can represent - Represent 99 and -99 in 2's complement format.
Determine the precise big-oh values : Determine the precise Big-Oh values for each of the following code samples, based on the number of statement executions - Remember to consider each statement in compound statements separately.
Which algorithm should be most efficient : the test conditions are equal for both algorithms, which algorithm should be most efficient when N is arbitrarily large (i.e., you can select N to be as large as you want it to be)?
Prepare an app that calculates the product of a series : Prepare an app that calculates the product of a series of integers that are passed to method   product using a variable-length argument list.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Why does the neverwet spray protect it from water

As is know, acetone is a polar molecule like water, so isn't it suppose to mix? So my question is: why does the Neverwet spray protect it from water but not from oils and detergents?

  Define a function hypotenuse that calculates the hypotenuse

Define a function hypotenuse that calculates the hypotenuse of a right triangle when the other two sides are given. The function should take two arguments and return the hypotenuse as a double.

  Implement class bankacct for bank of usq using bankacctcpp

implement class bankacct for bank of usq using bankacct.cpp and bankacct.h- the bsb for bank of usq at towoomba is

  Concept of object-oriented programming

Determine the manner in which each of the provided concepts relates to the concept of object-oriented programming. Justify your response - Analyze the fundamental manner in which they each relate to C++ coding of programs.

  Create a c++ console application

Objective: Create a C++ console application that will model the characteristics of a resistor. Create a multifile project. Create and add to the project an h file containing the resistor-class definition. Create and add to the project a cpp file cont..

  The grid is populated randomly

Initially, the grid is populated randomly with occupied and empty cells. Once the initial grid has been created, the program loops. Each iteration of the loop represents a tick or time step in the environment.

  Write a program that reads a string from the keyboard

Write a program that reads a string from the keyboard and then display all vowels contained within a user-input string. (Vowels are: a e i o u)

  Write a c program which takes a string from command line

Write a c program which takes a string from command line with mainfunction has no parameter and convert the string in upperca

  Demonstrate your code compiles and runs for a test case

Use a For loop to iterate through the array and input the values. Demonstrate your code compiles and runs for a test case of your choice.

  Write a c program to search a list of integers

Write a C program to search a list of integers for a particular value. The user should be prompted to enter the value to be searched for. Your program will then print out whether the value was found or not.

  C code christmas assignment

C code Christmas assignment. We are supposed to create a record generating programme that will accept user information and output student information (student grade, highest and lowest grade, pass or fail status). Must be done in modular form,..

  Provide an avenue for users to enter test data

Suggest an application system which is able to perform some arithmetic computations, like commission system, encryption system, timer system, etc, from anyone of the following industry.

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