Thanks to visit codestin.com
Credit goes to www.scribd.com

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

Final Project.

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views5 pages

Final Project.

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

#include <iostream>

using namespace std;

void loopPrintNumbers() {
for (int number = 1; number <= 10; number++) {
cout << number << " ";
}
cout << endl;
}

void loopSumOfNumbers() {
int limit, totalSum = 0;
cout << "enter n: ";
cin >> limit;
for (int count = 1; count <= limit; count++) {
totalSum += count;
}
cout << "sum = " << totalSum << endl;
}

void checkEvenOdd() {
int inputNumber;
cout << "enter a number: ";
cin >> inputNumber;
if (inputNumber % 2 == 0)
cout << "even" << endl;
else
cout << "odd" << endl;
}

void evaluateGrade() {
int score;
cout << "enter score: ";
cin >> score;
if (score >= 90)
cout << "grade: A" << endl;
else if (score >= 80)
cout << "grade: B" << endl;
else if (score >= 70)
cout << "grade: C" << endl;
else
cout << "grade: F" << endl;
}

void arrayInputAndPrint() {
int numbers[5];
cout << "wnter 5 numbers: ";
for (int index = 0; index < 5; index++) {
cin >> numbers[index];
}
cout << "you entered: ";
for (int index = 0; index < 5; index++) {
cout << numbers[index] << " ";
}
cout << endl;
}

void arrayFindMaximum() {
int values[5];
cout << "enter 5 numbers: ";
for (int index = 0; index < 5; index++) {
cin >> values[index];
}

int maximumValue = values[0];


for (int index = 1; index < 5; index++) {
if (values[index] > maximumValue) {
maximumValue = values[index];
}
}
cout << "maximum: " << maximumValue << endl;
}

int addNumbers(int first, int second) {


return first + second;
}

void performAddition() {
int numberA, numberB;
cout << "enter two numbers: ";
cin >> numberA >> numberB;
cout << "sum = " << addNumbers(numberA, numberB) << endl;
}

bool isPrimeNumber(int value) {


if (value <= 1) return false;
for (int divisor = 2; divisor * divisor <= value; divisor++) {
if (value % divisor == 0) return false;
}
return true;
}

void checkPrime() {
int candidate;
cout << "enter a number: ";
cin >> candidate;
if (isPrimeNumber(candidate))
cout << "prime" << endl;
else
cout << "not prime" << endl;
}

int main() {
int mainMenuChoice;

do
{
cout << "\nMain Menu:\n";
cout << "1. Looping Programs\n";
cout << "2. Conditional Programs\n";
cout << "3. Array Programs\n";
cout << "4. Function Programs\n";
cout << "0. Exit\n";
cout << "Enter your choice: ";
cin >> mainMenuChoice;

int subMenuChoice;
switch (mainMenuChoice) {
case 1:
cout << "1. print numbers 1-10\n2. sum of n numbers\nenter choice: ";
cin >> subMenuChoice;
if (subMenuChoice == 1) loopPrintNumbers();
else if (subMenuChoice == 2) loopSumOfNumbers();
else cout << "invalid choice!" << endl;
break;

case 2:
cout << "1. even or Odd\n2. Grade evaluation\nenter choice: ";
cin >> subMenuChoice;
if (subMenuChoice == 1) checkEvenOdd();
else if (subMenuChoice == 2) evaluateGrade();
else cout << "Invalid choice!" << endl;
break;

case 3:
cout << "1. input and print array\n2. Find Max in Array\nEnter choice: ";
cin >> subMenuChoice;
if (subMenuChoice == 1) arrayInputAndPrint();
else if (subMenuChoice == 2) arrayFindMaximum();
else cout << "Invalid choice!" << endl;
break;

case 4:
cout << "1. Add Numbers\n2. Prime Check\nEnter choice: ";
cin >> subMenuChoice;
if (subMenuChoice == 1) performAddition();
else if (subMenuChoice == 2) checkPrime();
else cout << "invalid choice!" << endl;
break;

case 0:
cout << "goodbye!" << endl;
break;

default:
cout << "invalid choice!" << endl;
}

} while (mainMenuChoice != 0);

return 0;
}

You might also like