|
void withdraw(double& balance, double amount)
12
|
bet | 5/6 | Sana | 22.02.2024 | Hajmi | 90,96 Kb. | | #160738 |
Bog'liq 1.1amaliy ish11void withdraw(double& balance, double amount)
12 {
13constdouble PENALTY = 10;
14if (balance >= amount)
15 {
16balance = balance - amount;
17 }
18else
19 {
20balance = balance - PENALTY;
21 }
22 }
23
24int main()
25 {
26double harrys_account = 1000;
27double sallys_account = 500;
28 withdraw(harrys_account, 100);
29// Now harrys_account is 900
30withdraw(harrys_account, 1000); // Insufficient funds
31// Now harrys_account is 890
32 withdraw(sallys_account, 150);
33 cout <<«Harry’s account: «<< harrys_account << endl; 34 cout <<«Sally’s account: «<< sallys_account << endl; 35
36return0;
37 }
program run
Harry’s account: 890 Sally’s account: 350
ch05/intname.cpp
1 #include
2 #include
3
4using namespace std;
5
6 /**
7Turns a digit into its English name.
8@param digit an integer between 1 and 9
9@return the name of digit (“one” ... “nine”)
10 */
11 string digit_name(int digit)
12 {
13if (digit == 1) return»one»; 14if (digit == 2) return»two»; 15if (digit == 3) return»three»;
16if (digit == 4) return»four»; 17if (digit == 5) return»five»; 18if (digit == 6) return»six»;
19if (digit == 7) return»seven»; 20if (digit == 8) return»eight»; 21if (digit == 9) return»nine»;
22return»«;
23 }
24
25 /**
26Turns a number between 10 and 19 into its English name.
27@param number an integer between 10 and 19
28@return the name of the given number (“ten” ... “nineteen”)
29 */
30 string teen_name(int number)
31 {
32if (number == 10) return»ten»;
33if (number == 11) return»eleven»;
34if (number == 12) return»twelve»;
35if (number == 13) return»thirteen»;
36if (number == 14)return»fourteen»;
37if (number == 15) return»fifteen»;
38if (number == 16) return»sixteen»;
39if (number == 17) return»seventeen»;
40if (number == 18) return»eighteen»;
41if (number == 19) return»nineteen»;
42return»«;
43 }
44
45 /**
46Gives the name of the tens part of a number between 20 and 99.
47@param number an integer between 20 and 99
48@return the name of the tens part of the number (“twenty” ... “ninety”) 49 */
50 string tens_name(int number)
51 {
52if (number >= 90) return»ninety»;
53if (number >= 80) return»eighty»;
54if (number >= 70) return»seventy»;
55if (number >= 60) return»sixty»;
56if (number >= 50) return»fifty»;
57if (number >= 40) return»forty»;
58if (number >= 30) return»thirty»;
59if (number >= 20) return»twenty»;
60return»«;
61 }
62
63 /**
64Turns a number into its English name.
65@param number a positive integer < 1,000
|
| |