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

  Taskwrite a bouncing ball video game the balls bounces

taskwrite a bouncing ball video game. the balls bounces within the screen where the two horizontal walls are fixed. the

  Recursive function returns number of vowels in a string

Write a recursive function, vowels, that returns the number of vowels in a string and write a program to test your function.

  Write a program that stores the number

Write a program that stores the following numbers in the array named miles : 15, 22, 16, 18, 27, 23, 20. Use a pointer to copy the data stored in miles to another array named dist and then display the values in the dist array.

  Allow single play a simple two dice game of chance against

Write a program that allows a single Player (the user) to play a simple two dice game of chance against

  Write down program in c for matrix multiplication program

write down program in c for matrix multiplication. program must accept dimension of both matrices to be multiplied and

  Ansi-c program complete assignment as follows in the

complete assignment as follows in the

  To overload a member function of the base class

To overload a member function of the base class A: the name of the function and the formal parameter list of the corresponding function in the derived class must be the same. B: the name of the function must be different

  Translate than c source code

Why does Ada take so much more time to translate than C source code? What phase of the Ada translation takes the longest?

  Write a program that uses the following arrays empid an

write a program that uses the following arrays empid an array of seven long integers to hold employee identification

  Write function that finds the minimum of three double value

1. Write a function that finds the minimum of three double values. This function should use another function that finds the minimum of two double values.

  Write the definition of the member function two of yclass

Write the definition of the member function two of yClass so that the private member variable a is initialized to the value of the first parameter of two, and the private member variable b is initialized to the value of the second parameter of two..

  Person class that includes fields for last name

Create a Person class that includes fields for last name, first name, and zip code. Include a default constructor that initializes last name, first name, and zip code to "X" if no arguments are supplied. Also include a display function. Write a ma..

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