Can someone please give me some problems or activities using if, else/if, and nested if statements???? i need 5 for each.. it would be better if u give the c++ codes for each problem..:)

this will be for my project.. hope u guyz helpme:icon_cheesygrin:

Dani AI

Generated

Following 's point about practising, here are five simple problem prompts for each construct (if, else/if, nested if) and compact C++ examples for one representative problem in each group. The prompts are beginner-friendly and suitable for a short school project.

If-only problems:

  • Check whether an integer is even.
  • Check whether an integer is positive.
  • Check whether a character is a vowel (a, e, i, o, u).
  • Check whether input equals zero.
  • Check whether a number is divisible by 3.
#include <iostream>

int main() {
    int n;
    std::cout << "Enter an integer: ";
    if (!(std::cin >> n)) return 0;
    if (n % 2 == 0) {
        std::cout << n << " is even\n";
    }
    return 0;
}

Else/if chain problems:

  • Convert numeric score to letter grade (A/B/C/D/F).
  • Classify a number as negative / zero / positive.
  • Map month number (1..12) to quarter (Q1..Q4).
  • Age category: child / teen / adult / senior.
  • Temperature classification: cold / mild / hot.
#include <iostream>

int main() {
    int score;
    std::cout << "Score (0-100): ";
    if (!(std::cin >> score)) return 0;
    if (score < 0 || score > 100) {
        std::cout << "Invalid score\n";
    } else if (score >= 90) {
        std::cout << "A\n";
    } else if (score >= 80) {
        std::cout << "B\n";
    } else if (score >= 70) {
        std::cout << "C\n";
    } else if (score >= 60) {
        std::cout << "D\n";
    } else {
        std::cout << "F\n";
    }
    return 0;
}

Nested-if problems:

  • Leap year check (divisible by 4, special rules for 100 and 400).
  • Validate username then password (check username, then nested password check).
  • Largest of three numbers using nested comparisons.
  • Triangle validity then type (equilateral / isosceles / scalene).
  • ATM withdrawal: check balance, then check denomination rules.
#include <iostream>

int main() {
    int year;
    std::cout << "Year: ";
    if (!(std::cin >> year)) return 0;
    if (year % 4 == 0) {
        if (year % 100 == 0) {
            if (year % 400 == 0) {
                std::cout << year << " is a leap year\n";
            } else {
                std::cout << year << " is not a leap year\n";
            }
        } else {
            std::cout << year << " is a leap year\n";
        }
    } else {
        std::cout << year << " is not a leap year\n";
    }
    return 0;
}

Quick tips: always use braces for clarity, validate input (check ranges and scan success), test edge cases (0, negatives, boundary scores), and keep indentation consistent so nested ifs remain readable.

Recommended Answers

All 2 Replies

ps....


SIMPLE problems only!! :)

We don't need to give you only. Cruise the posts and pick out a few you like!
And then do them yourself!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.