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:
commit
c09ce40be0
4048 files changed
+603256
No files matched your search
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,21 @@
|
||||
# Module 3
|
||||
|
||||
- Chapter 4 Decisions
|
||||
|
||||
## TODO
|
||||
|
||||
- Understanding decision structures also called conditional statements in C++.
|
||||
- Work with example code
|
||||
|
||||
## Readings
|
||||
|
||||
- eBook: Complete Chapter 4
|
||||
|
||||
## Module 3 Quiz
|
||||
|
||||
- **Take Module 3 Quiz on Moodle**
|
||||
- Quiz will cover the material in Chapter 4
|
||||
|
||||
## Module 3 Project
|
||||
|
||||
- **Project due this week**
|
||||
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"
|
||||
@@ -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";
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
Name:
|
||||
Class:
|
||||
Project:
|
||||
Last Date:
|
||||
*/
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
/// @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[])
|
||||
{
|
||||
char result;
|
||||
cout << "Do you want to get loopy? ";
|
||||
// is this an infinite loop?
|
||||
while (true)
|
||||
{
|
||||
cin >> result; // note that you must hit the enter key to process
|
||||
|
||||
if (result == 'y' || result == 'Y')
|
||||
{
|
||||
cout << "Continuing to the next iteration of the while loop ";
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Breaking out of the while loop ";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
Name:
|
||||
Class:
|
||||
Project:
|
||||
Last Date:
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/// @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[])
|
||||
{
|
||||
int choice; // To hold a menu choice
|
||||
int months; // To hold the number of months
|
||||
double charges; // To hold the monthly charges
|
||||
|
||||
// Constants for membership rates
|
||||
const double ADULT = 40.0,
|
||||
SENIOR = 30.0,
|
||||
CHILD = 20.0;
|
||||
|
||||
// Constants for menu choices
|
||||
const int ADULT_CHOICE = 1,
|
||||
CHILD_CHOICE = 2,
|
||||
SENIOR_CHOICE = 3,
|
||||
QUIT_CHOICE = 4;
|
||||
|
||||
// Display the menu and get a choice.
|
||||
cout << "\t\tHealth Club Membership Menu\n\n";
|
||||
cout << "1. Standard Adult Membership\n";
|
||||
cout << "2. Child Membership\n";
|
||||
cout << "3. Senior Citizen Membership\n";
|
||||
cout << "4. Quit the Program\n\n";
|
||||
cout << "Enter your choice: ";
|
||||
cin >> choice;
|
||||
|
||||
// Set the numeric ouput formatting.
|
||||
cout << fixed << showpoint << setprecision(2);
|
||||
|
||||
// Respond to the user's menu selection.
|
||||
if (choice == ADULT_CHOICE)
|
||||
{
|
||||
cout << "For how many months? ";
|
||||
cin >> months;
|
||||
charges = months * ADULT;
|
||||
cout << "The total charges are $" << charges << endl;
|
||||
}
|
||||
else if (choice == CHILD_CHOICE)
|
||||
{
|
||||
cout << "For how many months? ";
|
||||
cin >> months;
|
||||
charges = months * CHILD;
|
||||
cout << "The total charges are $" << charges << endl;
|
||||
}
|
||||
else if (choice == SENIOR_CHOICE)
|
||||
{
|
||||
cout << "For how many months? ";
|
||||
cin >> months;
|
||||
charges = months * SENIOR;
|
||||
cout << "The total charges are $" << charges << endl;
|
||||
}
|
||||
else if (choice == QUIT_CHOICE)
|
||||
{
|
||||
cout << "Program ending.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "The valid choices are 1 through 4. Run the\n";
|
||||
cout << "program again and select one of those.\n";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
Name:
|
||||
Class:
|
||||
Project:
|
||||
Last Date:
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <ctime>
|
||||
using namespace std;
|
||||
|
||||
/// @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[])
|
||||
{
|
||||
// note that without seeding the random number generator you will get the same random numbers every time
|
||||
int random_value_no_seed = rand() % 101; // Generate a random number between 0 and 100
|
||||
cout << random_value_no_seed << endl;
|
||||
|
||||
// uncomment the code below after running this code several times
|
||||
// srand(time(nullptr)); // use current time as seed for random generator
|
||||
// int random_value = rand() % 101;
|
||||
// cout << random_value << endl;
|
||||
|
||||
int lowerBound = 20, upperBound = 100;
|
||||
// This program will create some sequence of random
|
||||
// numbers on every program run within range lb to ub
|
||||
for (int i = 0; i < 50; i++)
|
||||
cout << (rand() % (upperBound - lowerBound + 1)) + lowerBound << " ";
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user