accept two numbers number 1 and number 2 and find the sum of all odd numbers between the two numbers entered

#include <iostream>
using namespace std;


int main()
{
    //a. Prompt the user to input two integers: firstNum and secondNum
    //(firstNum must be less than secondNum).
    cout << "a. Prompt the user to input two integers. First must be less than second\n";
    double firstNum = 2;
    double secondNum = 1;


    while (firstNum > secondNum)
    {
       cout << "enter first number: \n";
       cin >> firstNum;
       cout << "enter second number (must be more than first number): \n";
       cin >> secondNum;


       if (firstNum > secondNum) 
           cout << "first number must be less than second number. Try again. \n";
    }
    cout << "\n";


    //b. Output all odd numbers between firstNum and secondNum.
    cout << "b. Output all odd numbers between firstNum and secondNum.\n";
    int number = firstNum;


    while (number <= secondNum)
    {
        if (number % 2)
            cout << number++ << "\n";
        else
        {
            number++;
            continue;
        }
    }
    cout<<"\n";


    //c. Output the sum of all even numbers between firstNum and secondNum.
    cout << "c. Output the sum of all even numbers between firstNum and secondNum.\n";
    number = firstNum;
    int sum = 0;


    while (number <= secondNum)
    {
        if (!(number % 2))
            sum += number++;
        else
        {
            number++;
            continue;
        }
    }
    cout << "sum = " << sum << "\n\n";


    //d. Output the numbers and their squares between 1 and 10.
    cout << "d.Output the numbers and their squares between 1 and 10.\n";
    number = 1;
    while (number <= 10)
    {
        cout << number << " -> " << number << "^2" << " = " << number * number << '\n';
        number++;
    }
    cout << "\n";


    //e. Output the sum of the square of the odd numbers between firstNum and secondNum.
    cout << "Output the sum of the square of the odd numbers between firstNum and secondNum\n";
    number = firstNum;
    sum = 0;
    while (number <= secondNum)
    {
        if (number % 2)
        {
            sum += (number * number);
            number++;
        }
        else
        {
            number++;
            continue;
        }
    }
    cout << "sum: " << sum << "\n\n";


    //f. Output all uppercase letters.
    cout << "Output all uppercase letters.\n";
    int c = 65;


    while (c < 91)
        cout << char(c++) << ", ";
    cout << "\n";
}

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source