diff options
| author | austinlujan <[email protected]> | 2024-03-21 23:38:49 -0700 |
|---|---|---|
| committer | austinlujan <[email protected]> | 2024-03-21 23:38:49 -0700 |
| commit | d1347c4698a3d70e33c87ed1d95bc8af3c0844c6 (patch) | |
| tree | 2faf2b79bbf0f40d300ae3db40de53503485a92d /Project1/i.program.cpp | |
| parent | init commit (diff) | |
| download | homework-4-austinlujan-d1347c4698a3d70e33c87ed1d95bc8af3c0844c6.tar.xz homework-4-austinlujan-d1347c4698a3d70e33c87ed1d95bc8af3c0844c6.zip | |
Diffstat (limited to 'Project1/i.program.cpp')
| -rw-r--r-- | Project1/i.program.cpp | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/Project1/i.program.cpp b/Project1/i.program.cpp index e69de29..17179c1 100644 --- a/Project1/i.program.cpp +++ b/Project1/i.program.cpp @@ -0,0 +1,84 @@ +#include <iostream> + +//struct holding the users date of birth +struct UserBirthday { + int month; + int day; + int year; +}; + +// function that loops to print numbers 1-100 +void Print100() { + for (int i = 0; i <= 100; ++i) { + std::cout << i << std::endl; + } +} +//function to recieve user birth day/month/year and return a struct +UserBirthday InputBday() { + UserBirthday bday; + std::cout << "enter your birth day: "; + std::cin >> bday.day; + std::cout << "enter your birth month: "; + std::cin >> bday.month; + std::cout << "enter your birth year: "; + std::cin >> bday.year; + return bday; +} +// basic fibonacci sequence function +void fibonacci(size_t n) { + int a = 0, b = 1, c; + std::cout << "fibonacci sequence elements up to term number: " << n << std::endl; + for (size_t i = 0; i < n; ++i) { + std::cout << a << " "; + c = a + b; + a = b; + b = c; + } + std::cout << std::endl; +} + +int main() { + //loop to display menu and process user input while keeping them in menu until they choose exit + char userChoice; + do { + //manu options + std::cout << "options:" << std::endl; + std::cout << "a: print100" << std::endl; + std::cout << "b: input personal information" << std::endl; + std::cout << "c: print fibonacci" << std::endl; + std::cout << "d: exit" << std::endl; + std::cout << "choose: a, b, c, or d: "; + std::cin >> userChoice; + + // switch to give the user the right output for their aselection, added case insensitivity + switch (userChoice) { + case 'A': + case 'a': + Print100(); + break; + case 'B': + case 'b': { + UserBirthday userBday = InputBday(); + std::cout << "your birthday is: " << userBday.month << "/" << userBday.day << "/" << userBday.year << std::endl; + break; + } + case 'C': + case 'c': { + size_t n; + std::cout << "enter how many fibonacci terms: "; + std::cin >> n; + fibonacci(n); + break; + } + case 'D': + case 'd': + std::cout << std::endl << "exiting, goodbye" << std::endl << std::endl; + break; + default: + std::cout << std::endl << "invalid input" << std::endl << std::endl; + break; + } + } while (userChoice != 'D' && userChoice != 'd'); + + return 0; +}
\ No newline at end of file |