diff options
| author | Connor McDowell <[email protected]> | 2024-02-09 16:28:43 -0800 |
|---|---|---|
| committer | Connor McDowell <[email protected]> | 2024-02-09 16:28:43 -0800 |
| commit | 3ba2c8f72aafeadfaf3731fc684f428dbf29b957 (patch) | |
| tree | edc98d6a394cb69c3d5e0d9898e7ce1a345991cf /Project1/program.cpp | |
| parent | working on loops (diff) | |
| download | homework-4-connormcdowell275-3ba2c8f72aafeadfaf3731fc684f428dbf29b957.tar.xz homework-4-connormcdowell275-3ba2c8f72aafeadfaf3731fc684f428dbf29b957.zip | |
finished up! though considering what is practiced this week, i should've tried to do nesting for loops with "error handling" (its not actually, just a conditional to catch improper inputs) for selections, but expecting correct inputs following the messages would mean using if statements wouldrun smoother.HEADmain
Diffstat (limited to 'Project1/program.cpp')
| -rw-r--r-- | Project1/program.cpp | 57 |
1 files changed, 49 insertions, 8 deletions
diff --git a/Project1/program.cpp b/Project1/program.cpp index 3ac38af..3effd14 100644 --- a/Project1/program.cpp +++ b/Project1/program.cpp @@ -10,14 +10,56 @@ using std::cout; using std::cin; using std::endl; -void print100() { +int print100() { int i = 0; while (i < 101) { cout << i << " "; i++; } + if (i == 101) + { + cout << "\n"; + } + return 0; +} + +void printUser(userDoB newUser) +{ + cout << "User's birthday is: " << newUser.month << "/" << newUser.day << "/" << newUser.year << endl; +} + +userDoB inputPersonal() +{ + userDoB user = {}; + + cout << "\n Please enter just the day you were born as a number: "; + cin >> user.day; + + cout << "\n Please enter the month you were born as a number: "; + cin >> user.month; + + cout << "\n Now please enter the year you were born as a number: "; + cin >> user.year; + return user; } +int Fishonacci() { + int n; + cout << "please enter the term you would like to find in the Fibonacci sequence: "; + cin >> n; + + int a = 0, b = 1, c, i; + if (n == 0) + return a; + for (i = 2; i <= n; i++) + { + c = a + b; + a = b; + b = c; + } + cout << "The " << n << "th term in the Fibonacci sequence is: " << b << endl; + return 0; +} int main() { @@ -35,27 +77,26 @@ int main() if (t == 4) { i = 0; } - if (t != 1, 2, 3, 4) { - int main(); - } if (t == 1) { - void print100(); + print100(); + } if (t == 2) { int y; - userDoB inputPersonal(); + userDoB newUser = inputPersonal(); cout << "would you like to print your birthday? enter 1 for yes" << endl; cin >> y; if (y == 1) { - void printUser(); + printUser(newUser); } else { continue; } } if (t == 3) { - int Fishonacci(); + Fishonacci(); } + } |