Initial transfer of larger repo from git. IF full history and branches are needed must go to github at https://github.com/DulcisL/CCUCoding.git

This commit is contained in:
dolcel committed 2026-10-20 23:59:02 +00:00
commit c09ce40be0
4048 files changed
+603256

No files matched your search

Binary file not shown.
Binary file not shown.
@@ -0,0 +1,31 @@
# Module 3 Project
## Description
For this project create a menu that is displayed to the user that looks like this:
1. Guess a number game
2. Show lottery numbers
3. Exit
The menu should be created by a function that returns a string that contains the menu output.
Create two functions, one for each of the first two picks, that do the following:
Guess a number game:
prompt the user to guess a number between 0 and 100
On each guess tell the user if the guess was low or high or that they guessed the number
Show the user how many guesses it took to guess the number
Show lottery numbers
Create 5 numbers that can not be duplicates between 1 and 50
Show those numbers to the user
Name all functions appropriately.
## Deliverables
**Make sure and comment your code.**
Turn in your cpp file to moodle assignment "Module 3 Project"
+142
View File
@@ -0,0 +1,142 @@
/*
Name: Lakota Dolce
Class: CSCI207
Project: Project 3
Last Date: 9/8/2024
*/
#include <iostream>
#include <ctime>
using namespace std;
/// @brief
/// @param none
/// @return string of menu
int Menu(){
cout << "Welcome to the War Games \n";
cout << "Please choose from the following: \n";
cout << "1) Random Number Game \n2) Lottery \n3) Exit \n";
return 0;
}
/// @brief
/// @param none
/// @return nothing
int RandomNumber(){
// see modulo operator
int number = rand() %101;
int choice;
int guess = 0;
//Create loop to check user choice and rerun
while (choice != number){
cout << "Please choose a number between 0 and 100: \n";
//Get user choice
cin >> choice;
//Error check
if (cin.fail()){
//Clear cin so you don't get stuck in infinite loop
cin.clear();
cin. ignore(10000, '\n');
cout << "\n*That was not a valid choice* \n\n";
continue;
}
if (choice < 0 || choice > 100){
cout << "Your guess is not between 0 and 100 \n";
continue;
}
//Check if hi/lo and tell user
if (choice < number) {
cout << "Your guess was low \n";
guess +=1;
continue;
}
if (choice > number) {
cout << "Your guess was high \n";
guess +=1;};
continue;
}
cout << "\nCongratulations you guessed the number in ", guess, " guesses \n";
return 0;
}
/// @brief
/// @param none
/// @return none
int Lottery(){
// Create loop to get the numbers
cout << "The lucky numbers are: \n";
for (int i = 0; i < 5; i++) {
//Initialize
int upper = 50;
int lower = 0;
//Get random numbers
if (i == 4){
cout << "Drumroll please \n. \n. \n. \n";
}
cout << (rand() % (upper - lower + 1)) + lower << " \n";
}
return 0;
}
/// @brief
/// @param argc the number of arguments passed into main
/// @param argv the list of arguments passed into main
/// @return integer code indicating success or not
int main(int argc, char* argv[]){
//Create loop for game
while (true){
//Initialize
int choice;
// seed the random number machine
srand(time(nullptr));
//Print menu
Menu();
//take user choice
cin >> choice;
//Error check
if (cin.fail()){
//Clear cin so you don't get stuck in infinite loop
cin.clear();
cin. ignore(10000, '\n');
cout << "\n*That was not a valid choice* \n\n";
continue;
}
if (choice < 1 || choice > 3){
cout << "\n*That was not a valid choice* \n\n";
continue;
}
//Break sequence
if (choice == 3){
break;
}
//Check choice for game and run
if (choice ==1){
RandomNumber();
continue;
}
if (choice ==2){
Lottery();
continue;
}
}
cout << "\nGoodbye";
}