blob: 17179c10ff61457965451cbcfc10ae7e074cd5c2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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;
}
|