0% found this document useful (0 votes)
5 views5 pages

BT

The document contains four C++ programs. The first program generates a random subtraction problem, the second checks if a year is a leap year, the third calculates BMI based on user input, and the fourth simulates a lottery game with various prize levels based on user guesses. Each program includes basic input/output operations and conditional statements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

BT

The document contains four C++ programs. The first program generates a random subtraction problem, the second checks if a year is a leap year, the third calculates BMI based on user input, and the fourth simulates a lottery game with various prize levels based on user guesses. Each program includes basic input/output operations and conditional statements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

1/

#include <iostream>

#include <algorithm>

#include <ctime>

#include <cstdlib>

using namespace std;

int main() {

int num1 = rand() % 10;

int num2 = rand() % 10;

int num3 = 0;

char answer;

cout << "what is the number of " << num1 << "-" << num2 << endl;

if (num1 < num2) {

num3 = num1;

num1 = num2;

num2 = num3;

};

cin >> answer;

int m = num2 - num1;

if (answer == m) {

cout << "correct";

}
else {

cout << "incorrect";

return 0;

2/

#include <iostream>

using namespace std;

int main() {

int year;

cout << "enter year=" << endl;

cin >> year;

if (year % 4 == 0 && year % 100 ! =0);

cout << "this is leap year" << endl;

else {

cout << "this is not leap year" << endl;

return 0;

3/

#include <iostream>

#include <cmath>
using namespace std;

int main() {

double weightinPounds, heightinInches;

cout << "Enter weight in pounds: ";

cin >> weightinPounds;

cout << "Enter height in inches: ";

cin >> heightinInches;

double weightinKilograms = weightinPounds * 0.45359237;

double heightinMeters = heightinInches * 0.0254;

double bmi = weightinKilograms / pow(heightinMeters, 2);

cout << "Your BMI is: " << bmi << endl;

if (bmi < 18.5) {

cout << "Interpretation: Underweight" << endl;

else if (bmi >= 18.5 && bmi < 25.0) {

cout << "Interpretation: Normal" << endl;

else if (bmi >= 25.0 && bmi < 30.0) {

cout << "Interpretation: Overweight" << endl;

else {

cout << "Interpretation: Obese" << endl;

return 0;
}

4/

#include <iostream>

#include <cstdlib>

using namespace std;

int main() {

int lottery = rand() % 100;

int guess;

cout << "Enter your lottery pick (two digits): ";

cin >> guess;

int lotteryDigit1 = lottery / 10;

int lotteryDigit2 = lottery % 10;

int guessDigit1 = guess / 10;

int guessDigit2 = guess % 10;

if (guess == lottery) {

cout << "The lottery number is " << lottery << endl;

cout << "Exact match: you win $10,000!" << endl;

else if ((guessDigit1 == lotteryDigit2 && guessDigit2 == lotteryDigit1) ||

(guessDigit1 == lotteryDigit1 && guessDigit2 == lotteryDigit2)) {

cout << "The lottery number is " << lottery << endl;

cout << "Match all digits: you win $3,000!" << endl;

}
else if (guessDigit1 == lotteryDigit1 || guessDigit1 == lotteryDigit2 ||

guessDigit2 == lotteryDigit1 || guessDigit2 == lotteryDigit2) {

cout << "The lottery number is " << lottery << endl;

cout << "Match one digit: you win $1,000!" << endl;

else {

cout << "The lottery number is " << lottery << endl;

cout << "Sorry, no match." << endl;

return 0;

You might also like