1 00:00:00,000 --> 00:00:00,220 2 00:00:00,220 --> 00:00:02,860 SPEAKER 1:Let's write a program that gets an integer from the user, without 3 00:00:02,860 --> 00:00:05,820 using the CS50 libraries function, get int. 4 00:00:05,820 --> 00:00:08,570 To do this, we're going to use a new function called scan f. 5 00:00:08,570 --> 00:00:12,880 That it turns out, get int in the cs50 library users underneath the hood. 6 00:00:12,880 --> 00:00:13,980 Here we go. 7 00:00:13,980 --> 00:00:15,400 >> Let's first declared an int. 8 00:00:15,400 --> 00:00:17,110 Let's call it arbitrarily x. 9 00:00:17,110 --> 00:00:19,350 That will ultimately put the user's integer in. 10 00:00:19,350 --> 00:00:25,530 Let's now prompt the user for that number, as with number, please. 11 00:00:25,530 --> 00:00:28,280 And now let's call scan f, as follows. 12 00:00:28,280 --> 00:00:32,250 Scan f, quote unquote percent i, indicating that what I want to get 13 00:00:32,250 --> 00:00:34,040 from the user is indeed an integer. 14 00:00:34,040 --> 00:00:37,190 But now I need to provide storage space for that integer. 15 00:00:37,190 --> 00:00:40,830 I can't just pass in x, because recall that when you pass an argument to a 16 00:00:40,830 --> 00:00:43,080 function, it's typically passed by value. 17 00:00:43,080 --> 00:00:44,880 That is a copy is passed in. 18 00:00:44,880 --> 00:00:48,970 So instead, I want to provide scan f with the address of x so that it can 19 00:00:48,970 --> 00:00:51,840 actually change the value at that address. 20 00:00:51,840 --> 00:00:56,310 To achieve that, I simply need to pass in ampersand x in order to pass in the 21 00:00:56,310 --> 00:00:58,210 address of x. 22 00:00:58,210 --> 00:01:00,870 >> Lastly let's go ahead and print out for the user exactly 23 00:01:00,870 --> 00:01:02,160 what he or she typed. 24 00:01:02,160 --> 00:01:06,520 With print t, quote unquote, thanks for the-- percent i is our 25 00:01:06,520 --> 00:01:11,000 placeholder, followed by x this time, not ampersand x. 26 00:01:11,000 --> 00:01:14,570 Because, as always, I want to pass into print f exactly the value that I 27 00:01:14,570 --> 00:01:15,560 want printed. 28 00:01:15,560 --> 00:01:19,400 >> Let's now save, compile, and run this program. 29 00:01:19,400 --> 00:01:25,200 Make, scan f zero, dot slash, scan f zero, number please. 30 00:01:25,200 --> 00:01:27,790 Let's provide it with o 50. 31 00:01:27,790 --> 00:01:29,040 And thanks for the 50. 32 00:01:29,040 --> 00:01:31,563