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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
|
// CST116F2021-Lab3.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
//p.192
int input = 0, prev = 1, next = 1;
cout << "Please enter your ending number: ";
cin >> input;
if (input == 1)
cout << prev << ' ' << next;
else
{
cout << prev << " " << next << ' ';
while (next <= input)
{
next += prev;
cout << next << ' ';
if (prev == 1)
{
next += prev;
cout << next << ' ';
prev += prev;
}
else
{
next += prev;
cout << next << ' ';
prev += prev;
}
}
}
////p.184
//int length = 0;
//int height = 1;
//cout << "Please input the base length of your triangle: ";
//cin >> length;
//height = length;
//do {
// do
// {
// cout << '*';
// length = length--;
// } while (length != 0);
// cout << "\n";
// height = height--;
// length = height;
//} while (height != 0);
//return 0;
//p.179
/*int input = 0;
int remainder = 0;
cout << "Please enter an integer between 1 and 50: ";
cin >> input;
do
cout << "User input invalid. Please enter an integer between 1 and 50: ";
while (input < 1 || input > 50);
remainder = input % 2;
if(remainder != 0)
{
input = input--;
remainder = input % 2;
}
do
{
cout << input << ' ';
input = input - 2;
} while (input != 0);
return 0;*/
//p.177 8.2
/* int input = 0;
int remainder = 0;
cout << "Please enter an integer between 1 and 50: ";
cin >> input;
if (input < 1 || input > 50)
{
cout << "User input invalid. Exiting program.";
return -1;
}
remainder = input % 2;
if(remainder !=0)
{
input = input--;
remainder = input % 2;
}
while (input != 0)
{
cout << input << ' ';
input = input - 2;
}
cout << "0.";
return 0;*/
//p.168
//1. Take a loan within the correct bounds and calculate the interest and fees.
//2. Program takes 2 inputs, loan and interest rate. Loan can only be between 100 and 1000 dollars and between 1 and 18% interest rate. Display an error otherwise and end the program. Determine loan fees based on the loan amount. Calculate the interest and display loan, interest rate, and sum of the interest and fees.
//3.?
//4.
/*1. Define loan, interest rate, interest value, fees, and sum
* 2. Accept user inputs for loan and interest rate values
3. Compare loan and interest rate to set range
If not within range, output an error and end.
4. Compare loan to a range that determines the fees
5. Calculate the interest on the loan.
6. Print Loan, Interest Rate, and the sum of the interest and fees.*/
/*float loan = 0;
float rate = 0;
float interest = 0;
int fees = 0;
float sum = 0;
cout << "Please input the loan amount from 100 to 1,000 dollars: ";
cin >> loan;
if (loan >= 100 && loan <= 1000)
cout << "Please input the percent interest rate: ";
else
{
cout << "\nInvalid response. Ending program.\n";
return 1;
}
cin >> rate;
if (rate >= 1 && rate <= 18)
cout << "\nYour loan is for $" << loan << " at " << rate << "% interest.";
else
{
cout << "\nInvalid response. Ending program.\n";
return 2;
}
if (loan >= 100 && loan <= 500)
{
cout << "\nThere is a fee of $20 for a loan of this value.\n";
fees = 20;
}
else
{
cout << "\nThere is a fee of $25 for a loan of this value.\n";
fees = 25;
}
interest = loan * (rate/100);
sum = interest + fees;
cout << "\nYou have chosen a loan of $" << loan << " at an interest rate of " << rate << "%.\n";
cout << "Your interest and fees come to a total of $" << sum << ".\n";
return 0;*/
//p.161
/* int menu = 0;
cout << setw(38) << "Student Grade Program\n"
<< setw(35) << "- Main Menu -\n\n"
<< setw(27) << "1. Enter Name\n"
<< setw(34) << "2. Enter test scores\n"
<< setw(36) << "3. Display test scores\n"
<< setw(22) << "9. Exit\n\n"
<< setw(52) << "Please enter your choice from the list above: ";
cin >> menu;
switch (menu)
{
case 1:
cout << "\tYou have selected \"Enter name\"\n";
break;
case 2:
cout << "\tYou have selected \"Enter test scores\"\n";
break;
case 3:
cout << "\tYou have selected \"Display test scores\"\n";
break;
case 9:
cout << "\tYou have chosen to exit the program.\n";
break;
default:
cout << "\tInvalid selection.\n";
}
return 0;*/
//p.155
//int account = 0;
//float balance = 0;
//while (account != 1 && account != 2 && account != 3)
//{
// cout << "Enter 1 for Checking, 2 for Savings, or 3 for both: ";
// cin >> account;
// if (account == 1)
// cout << "You have a Checking account.";
// else if (account == 2)
// cout << "You have a Savings account.";
// else if (account == 3)
// cout << "You have both a Checking and Savings account.";
// else
// cout << "Error. Please enter a valid account type.";
//}
//cout << "\nPlease enter account balance: ";
//cin >> balance;
//if (balance >= 25000 && account == 3)
// cout << "You have a Platinum membership for Checking and Savings.";
//else if (balance < 25000 && balance >= 10000 && account == 3)
// cout << "You have a Gold membership for Checking and Savings.";
//else if (balance > 10000 && account != 3)
// if (account == 1)
// cout << "You have a Silver membership on a Checking account.";
// else
// cout << "You have a Silver membership on a Savings account.";
//else
// if (account == 1)
// cout << "You have a Copper membership on a Checking account.";
// else
// cout << "You have a Copper membership on a Savings account.";
//
//cout << "\n";
//return 0;
}
|