aboutsummaryrefslogtreecommitdiff
path: root/homework 4/program.cpp
blob: 4c3f4200b2a290345bda9d87e3bcedef8eb4ee3d (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Name: Nataliia Brown
// Date: 2/5/24
// Class: CST 116
// Assignment: Homework 4

#include <iostream>

using std::cout;
using std::cin;
using std::endl;


void Menu() {
	cout << endl << endl << "Choose an option: enter 1 for A, 2 for B, 3 for C or 4 for D" << endl;
	cout << "A. Print100" << endl;
	cout << "B. Input Personal Information" << endl;
	cout << "C. Print Fibonacci" << endl;
	cout << "D. Exit" << endl;
}

void Print100(size_t n) {
	for (int j = 0; j <= n; j++) {
		cout << j << " ";
	}
	cout << endl;
}

void PrintFibonacci(size_t n) {
	int k, t1 = 0, t2 = 1, nextTerm = 0;

	cout << "Enter the number of terms: ";
	cin >> k;

	cout << "Fibonacci Series: ";

	for (int i = 1; i <= k; ++i) {
		
		if (i == 1) {
			cout << t1 << " ";
			continue;
		}
		if (i == 2) {
			cout << t2 << " ";
			continue;
		}
		nextTerm = t1 + t2;
		t1 = t2;
		t2 = nextTerm;

		cout << nextTerm << " ";
	}


}

struct UserDob
{
	int day;
	int month;
	int year;
};

UserDob InputPersonalInfo()
{
	UserDob user = {};

	cout << "\nDay: ";
	cin >> user.day;

	cout << "Month: ";
	cin >> user.month;

	cout << "Year: ";
	cin >> user.year;

	return user;

}

void PrintUserInfo(UserDob newUser) {

	cout << "User's DOB: " << newUser.month << "/" << newUser.day << "/" << newUser.year << endl;
}

int main() {
	int i;
	Menu();
	cin >> i;
	

	while (i != 4) {
		system("cls");
		if (i == 1)

		{
			cout << "Enter the number for Print 100 function: ";
			int n;
			cin >> n;
			Print100(n);
		}
		else if (i == 2)
		{
			UserDob newUser = InputPersonalInfo(); 
			PrintUserInfo(newUser);
		}
		else if (i == 3)
		{
			PrintFibonacci(i);
		}
		
		
		int j;
		Menu();

		cin >> j;
		i = j;
	}
	
	return 0;
}