Skip to content

Commit e5fc3ce

Browse files
committed
Update chapter 3
1 parent fc28c35 commit e5fc3ce

File tree

3 files changed

+48
-14
lines changed

3 files changed

+48
-14
lines changed

week03/Lecture03.pptx

8.45 KB
Binary file not shown.

week03/examples/goto.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
float mysquare(float value)
6+
{
7+
float result = 0.0f;
8+
9+
if(value >= 1.0f || value <= 0)
10+
{
11+
cerr << "The input is out of range." << endl;
12+
goto EXIT_ERROR;
13+
}
14+
result = value * value;
15+
return result;
16+
17+
EXIT_ERROR:
18+
//do sth such as closing files here
19+
return 0.0f;
20+
}
21+
22+
int main()
23+
{
24+
float value;
25+
cout << "Input a floating-point number." << endl;
26+
cin >> value;
27+
28+
float result = mysquare(value);
29+
30+
if (result > 0)
31+
cout << "The square is " << result << "." << endl;
32+
33+
return 0;
34+
}

week03/examples/while.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ int main()
99
num--;
1010
}
1111

12-
num = 10;
13-
do
14-
{
15-
cout << "num = " << num << endl;
16-
num--;
17-
}while (num > 0);
12+
// num = 10;
13+
// do
14+
// {
15+
// cout << "num = " << num << endl;
16+
// num--;
17+
// }while (num > 0);
1818

19-
num = 10;
20-
while (num > 0)
21-
{
22-
cout << "num = " << num << endl;
23-
num--;
24-
if (num == 5)
25-
break;
26-
}
19+
// num = 10;
20+
// while (num > 0)
21+
// {
22+
// if (num == 5)
23+
// break;
24+
// cout << "num = " << num << endl;
25+
// num--;
26+
// }
2727
return 0;
2828
}

0 commit comments

Comments
 (0)