#include <iostream>
//PANG GENERATE NG RANDOM NUMBER
#include <stdlib.h>
#include <time.h>
using namespace std;
void program1() {
char confirm;
do {
cout << "\nEnter non-negative numbers\n";
int total = 0, input;
for (int i = 1; i <= 3; i++) {
cout << i << "). Enter a number: ";
cin >> input;
if (input < 0)
{
cout << "Number must be non-negative\n";
i = (i - 1) < 1 ? 0 : i - 1;
}
else {
total = total + input;
}
}
cout << "Sum of numbers: " << total << "\n";
cout << "Would you like to enter another 3 sets of numbers? [y/n]: ";
cin >> confirm;
} while (confirm == 'y' || confirm == 'Y');
}
void program2() {
int star;
int limit =14;
cout <<"\nEnter star numbers (max "<< limit << "): ";
cin >> star;
if (star > limit)
{
cout << "Input exceeded limit(" << limit << ")\n";
}
else {
for (int i = 1; i <= star; i++)
{
for (int x = 0; x < i; x++)
{
cout << "*";
}
cout << "\n";
}
}
}
void program3() {
char confirm = 'y';
cout << "\nEnter number must be a non-negative and does not exceed 20\n";
while (confirm == 'y' || confirm == 'Y')
{
int x, y;
cout << "Enter box length: ";
cin >> x;
if (x < 0 || x > 20)
{
cout << "Invalid Input";
break;
}
cout << "Enter box height: ";
cin >> y;
if (y < 0 || y > 20)
{
cout << "Invalid Input";
break;
}
for (int i = 0; i < x; i++)
{
cout << "*";
}
cout << "\n";
for (int i = 0; i < y-2; i++)
{
cout << "*";
for (int i = 0; i < x-2; i++)
{
cout << " ";
}
cout << "*\n";
}
for (int i = 0; i < x; i++)
{
cout << "*";
}
cout << "\nWould you like to make another square?[y/n]: ";
cin >> confirm;
}
}
void program4() {
int number, input, player = 2, maxrand;
cout << "Welcome to guess the number! the player who correctly guesses the number wins!\n";
cout << "Please enter the max number: ";
cin >> maxrand;
srand(time(NULL));
number = rand() % maxrand;
do {
cout << "\n";
if (player == 2)
{
cout << "Player 1: ";
player = 1;
}
else {
cout << "Player 2: ";
player = 2;
}
cin >> input;
if (number < input) {
cout << "Number is lower!\n";
}
else if (number > input) {
cout << "Number is higher!\n";
}
} while (number != input);
cout << "Congratulations! Player " << player << " Won! Yay!!\n=====";
}
int main()
{
char input, confirm;
cout << "Welcome to 4-in 1 program simulator!\n";
do
{
do {
cout << "\nType the letter of your choice: \n";
cout << "\ta.) Sum of three Integers\n";
cout << "\tb.) Star generator\n";
cout << "\tc.) Box virtualizer\n";
cout << "\td.) Guess the number\n";
cout << "Your choice: ";
cin >> input;
putchar(tolower(input));
switch (input)
{
case 'a':
program1();
break;
case 'b':
program2();
break;
case 'c':
program3();
break;
case 'd':
program4();
break;
default:
cout << "Invalid input";
break;
}
}while(input == 'a' || 'b' || 'c' || 'd');
if (input != 'a' || 'b' || 'c' || 'd')
{
cout << "\nInvalid input! \n";
}
cout << "Would you like to play another one? [y/n]: ";
cin >> confirm;
putchar(tolower(confirm));
} while (confirm == 'y');
return 0;
}