1
00:00:01,160 --> 00:00:09,380
OK, so now we're going to take a break from just doing standard lecture and we are going to do some

2
00:00:09,380 --> 00:00:11,570
practice problems, and this is really important.

3
00:00:11,580 --> 00:00:19,360
Honestly, this is probably where the bulk of actual learning really takes place in programming.

4
00:00:19,370 --> 00:00:30,710
So it's great that I'm able to tell you some things about C++ and programming in general, but I feel

5
00:00:30,710 --> 00:00:36,710
like it doesn't really get absorbed until you're actually solving problems on your own.

6
00:00:37,520 --> 00:00:46,340
So what I'm going to do, of course, this course will have some problems that I can just assign as

7
00:00:46,340 --> 00:00:54,860
coding exercises through you to me or I can also, you know, I also have some projects set aside where

8
00:00:54,860 --> 00:01:04,490
I have like a document that has a big project description and you will implement a project if you want

9
00:01:04,490 --> 00:01:05,780
to, of course, which you should.

10
00:01:07,220 --> 00:01:08,590
But that'll come later in the course.

11
00:01:08,600 --> 00:01:14,150
Right now, we're just going to kind of try and use what we've learned so far so we can get better at

12
00:01:14,150 --> 00:01:14,270
it.

13
00:01:15,730 --> 00:01:18,820
So let's go ahead and do that, I have two problems today.

14
00:01:19,510 --> 00:01:26,950
What I'm going to do is have a slide that will have the problem, statement a description of the problem

15
00:01:26,950 --> 00:01:30,250
and show you some sample output, some input and output.

16
00:01:31,360 --> 00:01:39,850
And then you're going to pause the video if you like and try and solve the problem on your own.

17
00:01:39,850 --> 00:01:43,240
And then afterwards, I will walk through it.

18
00:01:44,110 --> 00:01:46,630
So let's go ahead and get started.

19
00:01:47,590 --> 00:01:48,880
So first problem here.

20
00:01:49,360 --> 00:01:54,540
This one involves user input and conditionals and output.

21
00:01:54,550 --> 00:01:56,230
So these are three things that we've learned.

22
00:01:56,230 --> 00:02:03,940
We just went over a user input and conditionals would be if, else, if and else and output is something

23
00:02:03,940 --> 00:02:06,010
we've been doing for a long time now, a CEO, right?

24
00:02:07,270 --> 00:02:13,930
So and the description is to create a program that reads in two characters and two integers.

25
00:02:15,080 --> 00:02:20,870
The program should then check to see if either of the characters match either of the integers.

26
00:02:22,090 --> 00:02:29,840
So this is possible because in C++, you can compare chars and and hence that ASCII table.

27
00:02:29,860 --> 00:02:36,070
You notice that there's a decimal value for each of those characters, so you're able to compare an

28
00:02:36,070 --> 00:02:41,020
integer which represents kind of a decimal value and the decimal value of the characters, so you can

29
00:02:41,020 --> 00:02:43,420
use that ASCII table for reference.

30
00:02:43,420 --> 00:02:46,610
If this is confusing, it might be good to use it either way.

31
00:02:46,630 --> 00:02:46,950
Right?

32
00:02:46,960 --> 00:02:49,990
So you can actually check your output to make sure it's correct.

33
00:02:50,650 --> 00:02:57,880
So you look at the decimal value of a certain character, and then you can enter some input and check

34
00:02:57,880 --> 00:03:03,640
the ASCII table to see if the match is actually correct when your program is deciding if something matched.

35
00:03:05,290 --> 00:03:10,150
So if anything matches, then what you should do is print out the characters, then match so and also

36
00:03:10,150 --> 00:03:13,320
try and follow the input output format that I have mentioned here.

37
00:03:13,330 --> 00:03:23,490
Here's some example stuff so you don't have to use this same input that I'm using.

38
00:03:23,500 --> 00:03:30,250
You can test it with whatever input you like, but this is kind of what should print out right here

39
00:03:30,250 --> 00:03:30,850
is what it means.

40
00:03:30,860 --> 00:03:37,900
So you should say into two characters, followed by two ends and then a colon, and then you can enter

41
00:03:37,900 --> 00:03:39,220
the input, whatever you like.

42
00:03:39,700 --> 00:03:44,830
And then then what should happen is it should print something out like this.

43
00:03:44,830 --> 00:03:55,690
For this example, be has a ASCII decimal value as ninety eight, so be it was matched with ninety eight.

44
00:03:56,050 --> 00:03:59,740
So that's why it printed out B has a decimal value matching ninety eight.

45
00:04:01,630 --> 00:04:08,590
So, you know, this one has no matches, and then this one m matches 77, so that's why I printed this

46
00:04:08,590 --> 00:04:09,070
out here.

47
00:04:11,260 --> 00:04:14,440
OK, so hopefully that makes sense to you.

48
00:04:15,100 --> 00:04:18,160
If you are ready, you can go ahead and pause the video.

49
00:04:18,650 --> 00:04:24,550
Try and pull up an editor and see if you can figure this out for yourself.

50
00:04:25,150 --> 00:04:29,410
Otherwise, I'm going to go ahead and walk through it.

51
00:04:29,410 --> 00:04:37,780
But I really, really think you should try and solve this for yourself, because that is where the actual

52
00:04:37,780 --> 00:04:39,420
learning will happen.

53
00:04:39,430 --> 00:04:46,450
You know, it's all about getting problems like this, and you know, this is a pretty straightforward

54
00:04:46,450 --> 00:04:47,220
problem.

55
00:04:47,230 --> 00:04:50,680
We'll be looking at much more complex problems in the future.

56
00:04:51,610 --> 00:04:57,460
But that everything is going to be challenging, but the more challenging it is, honestly, the better

57
00:04:57,460 --> 00:05:00,070
it is because it really pushes you to be a better programmer.

58
00:05:00,070 --> 00:05:07,180
So try and do the best you can on this, even if you can't figure it out or if it has errors, do all

59
00:05:07,180 --> 00:05:08,890
of the parts that you can.

60
00:05:10,190 --> 00:05:12,350
And just kind of do the best you can is what I mean.

61
00:05:12,470 --> 00:05:17,090
And then I will go ahead and go over it and we can fill in any of the gaps that you might have had.

62
00:05:18,020 --> 00:05:25,010
OK, so go ahead and post the video if you haven't otherwise, I'm going to go ahead and pull up an

63
00:05:25,010 --> 00:05:27,290
editor and try and solve this.

64
00:05:28,590 --> 00:05:29,580
So we can go over it.

65
00:05:31,940 --> 00:05:34,520
So I have the code here.

66
00:05:35,730 --> 00:05:38,640
Open and I just have sort of a skeleton of a program.

67
00:05:40,000 --> 00:05:48,270
So let's also toggle back and forth kind of between the presentation and oh, so this right here it

68
00:05:48,280 --> 00:05:52,110
said that it needs to read in two characters and to integers.

69
00:05:52,110 --> 00:05:54,240
So we're kind of going to break this down.

70
00:05:54,870 --> 00:05:57,810
So we already got a skeleton of a main function there.

71
00:05:59,370 --> 00:06:01,280
But let's go ahead and do this first.

72
00:06:01,290 --> 00:06:02,590
This is something easy, right?

73
00:06:02,610 --> 00:06:08,970
We know that we're going to need to read into two characters in two integers, so we're going to have

74
00:06:08,970 --> 00:06:10,680
to make those variables right.

75
00:06:11,790 --> 00:06:13,260
So let's go ahead and make that.

76
00:06:13,260 --> 00:06:23,250
So I'm going to say Char C one and Charge C two and end one and two.

77
00:06:24,150 --> 00:06:28,440
So now we have some variables, so let's see what it says next.

78
00:06:29,550 --> 00:06:35,280
So the program, it's going to read into this, then it should check to see if either of the characters

79
00:06:35,880 --> 00:06:37,680
match either of the integers.

80
00:06:39,190 --> 00:06:44,170
OK, so let's break this down and just kind of do this next part.

81
00:06:44,200 --> 00:06:49,420
This is something else that we know how to do before we do the matching part that's probably like the

82
00:06:49,420 --> 00:06:49,960
hardest.

83
00:06:50,830 --> 00:06:52,760
We know we got to read them in, right?

84
00:06:52,780 --> 00:06:57,150
So let's go ahead and create some scene.

85
00:06:57,160 --> 00:07:02,830
And also, we should probably make some see out stuff to print a message to the user telling them what

86
00:07:02,830 --> 00:07:03,340
to do.

87
00:07:05,790 --> 00:07:12,360
So I'm going to go ahead and do sit out and just say, let's see what we have here.

88
00:07:12,670 --> 00:07:23,970
Enter two characters, followed by two it's OK to enter two characters, so followed by two ends.

89
00:07:25,710 --> 00:07:27,750
And I think there's a little space here.

90
00:07:31,020 --> 00:07:36,200
OK, so we print that out and then our next thing is to read into this.

91
00:07:36,210 --> 00:07:38,010
So it's the character's first.

92
00:07:38,490 --> 00:07:44,970
So I'm going to scene to see one and then we'll have see two.

93
00:07:45,600 --> 00:07:47,570
And then after that comes in two ends, right?

94
00:07:47,580 --> 00:07:49,740
So we will do our one.

95
00:07:50,430 --> 00:07:51,420
And I too.

96
00:07:54,780 --> 00:07:55,200
Cool.

97
00:07:55,380 --> 00:07:59,040
So let's go ahead and go back to the problem description.

98
00:07:59,040 --> 00:07:59,610
So.

99
00:08:01,810 --> 00:08:07,270
We're now reading in this whole thing, so we're reading in the two characters and two integers, we

100
00:08:07,270 --> 00:08:07,900
did that part.

101
00:08:10,310 --> 00:08:17,600
So the program should check to see if either the characters match either the integers, so how can we

102
00:08:17,600 --> 00:08:18,860
do this part?

103
00:08:19,640 --> 00:08:21,230
We know we can compare them.

104
00:08:22,400 --> 00:08:27,260
So if we're going to be checking to see whether.

105
00:08:28,780 --> 00:08:34,600
Something is matching that kind of implies that we're going to need to use some conditionals, we need

106
00:08:34,600 --> 00:08:36,430
to check whether something's true or not.

107
00:08:36,460 --> 00:08:36,760
Right?

108
00:08:39,000 --> 00:08:42,120
So we're going to go ahead and use some conditional statements for this.

109
00:08:43,830 --> 00:08:46,210
So how should we set this up, set this up?

110
00:08:46,230 --> 00:08:49,680
Well, let's start out with just an if the first thing, right?

111
00:08:50,430 --> 00:08:53,790
And then we'll just kind of have to.

112
00:08:55,110 --> 00:09:01,680
Cover all the different options, right, because what can happen is this character could be matching

113
00:09:01,680 --> 00:09:05,150
this and or this character could be matching this and.

114
00:09:06,260 --> 00:09:10,820
And then this character could be matching this and or this character could be matching this, and so

115
00:09:10,820 --> 00:09:19,490
we kind of have like four options for matching and then we have another option in which none of them

116
00:09:19,490 --> 00:09:19,890
match.

117
00:09:19,970 --> 00:09:23,750
So those are actually five different conditions, right?

118
00:09:25,700 --> 00:09:28,460
So I'm just going to do all of these different.

119
00:09:30,460 --> 00:09:41,170
Conditions, I think you could do just multiple ifs, but I think I'm going to use an elusive because

120
00:09:41,170 --> 00:09:42,820
it only says that.

121
00:09:45,700 --> 00:09:51,130
So it's says if either of the characters match either of the integers.

122
00:09:53,540 --> 00:10:01,180
So I think that maybe we should just use this because there could also be a a chance in which both match,

123
00:10:01,190 --> 00:10:08,090
so maybe there's even some more, so this could match this one or this one and this could match this

124
00:10:08,090 --> 00:10:14,030
one or this one, and then we could have both matching like maybe let's see.

125
00:10:16,580 --> 00:10:16,970
Yeah.

126
00:10:17,060 --> 00:10:20,570
So I think that, you know, we can have conditions that cover those four.

127
00:10:20,600 --> 00:10:22,190
There's those four matching conditions.

128
00:10:22,520 --> 00:10:28,160
But if we leave them is if we leave them as if just instead of exclusive, we're so elusive.

129
00:10:29,690 --> 00:10:36,230
Then that will open up the possibility that we could print out that maybe multiple match, so like a

130
00:10:36,230 --> 00:10:41,570
C one matches this, for example, and then see two matches this, then they would both print out.

131
00:10:41,570 --> 00:10:47,030
If we did El Sift's, then it would only let one thing print out.

132
00:10:48,170 --> 00:10:52,220
So I think I'm just going to do a bunch of ifs.

133
00:10:52,220 --> 00:10:54,560
So for us, for that and for that condition.

134
00:10:54,560 --> 00:11:03,390
So I will say if I see one.

135
00:11:03,410 --> 00:11:06,950
So let's just start out with this basic one is one equals I one.

136
00:11:09,360 --> 00:11:19,260
And you may be thinking, well, couldn't we just do something like C1 equals A1 or C two equals, you

137
00:11:19,260 --> 00:11:26,070
know, equals A1 or, you know, dot dot, dot and just do all of them in one condition.

138
00:11:27,390 --> 00:11:28,230
You could do that.

139
00:11:28,710 --> 00:11:34,740
But think about what you need to print out, so you notice that you actually have to.

140
00:11:34,770 --> 00:11:40,200
If we look ahead, kind of, you have to print out the things that match.

141
00:11:41,400 --> 00:11:45,390
So if you were to put this all in one condition.

142
00:11:47,120 --> 00:11:49,940
And it's like this or this or this or this.

143
00:11:50,220 --> 00:11:51,560
What are you going to print out?

144
00:11:51,890 --> 00:11:56,130
How are you going to know which you know which one matched?

145
00:11:56,150 --> 00:12:02,990
Because if one of these was to be true, like, for example, let's say sea one equals I one is false,

146
00:12:02,990 --> 00:12:04,190
but C two equals nine.

147
00:12:04,190 --> 00:12:04,940
One is true.

148
00:12:05,510 --> 00:12:06,540
How do you know?

149
00:12:07,610 --> 00:12:15,770
You know, how do you know which one to use the variables for to print out this result that says, you

150
00:12:15,770 --> 00:12:19,040
know, blank has a decimal value matching blank?

151
00:12:20,400 --> 00:12:22,950
That's why we need to separate these into different issues.

152
00:12:24,570 --> 00:12:27,750
So I'm going to do that, I'm going to say C one equals I one.

153
00:12:28,470 --> 00:12:31,560
And then what we will do is just print out

154
00:12:35,490 --> 00:12:43,500
that this c one right is has a decimal value matching i1.

155
00:12:44,840 --> 00:12:48,410
So these are variables that we can print out, right?

156
00:12:49,010 --> 00:12:52,850
Because in this example, be matched ninety eight.

157
00:12:53,030 --> 00:12:55,110
We don't have to know like, um.

158
00:12:57,110 --> 00:13:02,150
You know about the specific values that someone's entering, we can just use the variables because if

159
00:13:02,240 --> 00:13:07,820
someone is equal to everyone, then we know that these are the two things we're going to want to print

160
00:13:07,820 --> 00:13:09,740
out to the console as our result.

161
00:13:10,790 --> 00:13:16,310
So we'll say see one and then has only seen one go back to.

162
00:13:16,310 --> 00:13:23,720
This has a dismal value matching as a decimal in value matching and then a space.

163
00:13:24,230 --> 00:13:27,470
And then I'll say I won and then and enduring.

164
00:13:30,140 --> 00:13:30,530
Cool.

165
00:13:30,560 --> 00:13:36,950
So then we're going to be doing like a very similar thing for the other three conditions, so I'm just

166
00:13:36,950 --> 00:13:38,180
going to copy paste

167
00:13:41,840 --> 00:13:43,370
that didn't paste very nice.

168
00:13:46,130 --> 00:13:48,320
You see if I can copy paste that again.

169
00:13:52,390 --> 00:13:54,100
OK, so it just has a.

170
00:13:57,150 --> 00:13:58,380
Just need to back that up.

171
00:14:00,210 --> 00:14:08,670
So I'm going to go ahead and paste some more just because I know I'm going to be doing this for three

172
00:14:08,670 --> 00:14:10,410
other conditions.

173
00:14:15,680 --> 00:14:25,340
But I'm going to be changing these up, so this next one, I'm going to put C one equals I two.

174
00:14:26,300 --> 00:14:28,840
And then I can just change things like this.

175
00:14:33,400 --> 00:14:35,180
I don't have that over to make it look better.

176
00:14:35,540 --> 00:14:37,430
And then let's see a little through this next one.

177
00:14:37,430 --> 00:14:41,990
This will be a see two equals i two.

178
00:14:43,840 --> 00:14:51,880
So we can just change these down here, and this will be or actually, no, I make this, I want to

179
00:14:51,880 --> 00:14:53,290
see two equals I one.

180
00:14:55,080 --> 00:14:59,910
And then this is going to be key to equaling I to.

181
00:15:15,520 --> 00:15:24,460
OK, so if it has a decimal value matching any one of these, it can print out, you know, both of

182
00:15:24,460 --> 00:15:24,820
them.

183
00:15:26,780 --> 00:15:33,740
So the next thing that we have to do, though, is figure out if it doesn't match any of these.

184
00:15:34,790 --> 00:15:36,470
Then what are we going to do?

185
00:15:37,410 --> 00:15:39,660
So if we just put in else right here.

186
00:15:41,680 --> 00:15:42,850
It'll basically.

187
00:15:46,710 --> 00:15:54,240
Just like, you know, if I just put an else right here, it'll only be attached to this Earth right

188
00:15:54,240 --> 00:16:00,330
here, so it only run the health if this is not true, which is totally possible.

189
00:16:00,960 --> 00:16:04,860
But what if one of these matches, you know, above it, we win.

190
00:16:05,130 --> 00:16:09,780
We're not going to want to like, go down here and let's say this matched.

191
00:16:09,780 --> 00:16:14,340
So says, Oh, you know, see two as decimal value matching I one.

192
00:16:14,340 --> 00:16:18,060
But then we get down here and it's like, Oh, well, see, two is not equal to two.

193
00:16:19,020 --> 00:16:22,950
And so if this is false and it just jumped in the Earth and will be like nothing, just matching, we

194
00:16:22,950 --> 00:16:27,480
don't want that because something did match right in that example I was talking about.

195
00:16:29,650 --> 00:16:32,480
So we kind of have multiple options.

196
00:16:32,500 --> 00:16:38,710
If you wanted to kind of put a ton of code, you could just put it in, you know?

197
00:16:40,430 --> 00:16:43,280
A bunch of like aliases after.

198
00:16:44,470 --> 00:16:49,540
After these things, you know, or some other big condition, you know, if you put it loss after each

199
00:16:49,540 --> 00:16:52,840
one of these, then it would just run after each one if it was false anyway.

200
00:16:52,840 --> 00:16:54,160
So we don't want to do that.

201
00:16:54,610 --> 00:16:59,230
So what I think we should do is instead have an else if.

202
00:17:02,420 --> 00:17:07,430
And then we can say, you know, if none of these are matching.

203
00:17:09,140 --> 00:17:13,010
Then we're going to print out that none of them match.

204
00:17:13,820 --> 00:17:15,470
And so this is kind of long.

205
00:17:15,590 --> 00:17:18,800
But, you know, we're just starting out, so it's fine.

206
00:17:20,210 --> 00:17:27,350
So we're going to make a I'm going to make actually a big condition here where I do this, but I just

207
00:17:27,350 --> 00:17:34,280
change it to not equal and never put in or.

208
00:17:35,620 --> 00:17:41,800
And so I'm going to copy all of these and just change it to not equal.

209
00:17:53,010 --> 00:17:58,080
So if I just keep passing these and I can go back and change it to not equal.

210
00:17:59,500 --> 00:18:07,960
So I actually already have that one, so I'm going to copy this one, so it'll just be for four of these

211
00:18:07,960 --> 00:18:09,460
with eight not equal, so.

212
00:18:09,910 --> 00:18:17,950
And it's not yours, actually, I bet this is going to be and because if all of these are false.

213
00:18:19,910 --> 00:18:23,220
And what I mean is that they're not equal.

214
00:18:23,240 --> 00:18:27,860
I don't mean that this evaluates to false, I mean that the equal evaluates to false.

215
00:18:29,690 --> 00:18:33,110
So if none of these are equal.

216
00:18:35,460 --> 00:18:38,730
So that would mean that this not equal thing is true, right?

217
00:18:39,270 --> 00:18:47,910
So if this is not equal and this is not equal and this is not equal and this is not equal, that means

218
00:18:47,910 --> 00:18:52,410
that all the possible matches that you could have are.

219
00:18:53,480 --> 00:18:54,100
False.

220
00:18:55,010 --> 00:19:02,510
And so then you can say that nothing matches which what we have down here is there are no matching characters

221
00:19:02,510 --> 00:19:03,440
and integers.

222
00:19:06,640 --> 00:19:09,220
So that's what we'll go ahead and print out in this case.

223
00:19:20,350 --> 00:19:23,860
So we'll just print that out if this is the case.

224
00:19:24,860 --> 00:19:25,120
Right.

225
00:19:28,130 --> 00:19:28,520
Cool.

226
00:19:28,550 --> 00:19:32,510
So I think that that should probably cover it.

227
00:19:33,570 --> 00:19:37,620
We can go ahead and test it now in this example.

228
00:19:38,010 --> 00:19:39,180
I just called this.

229
00:19:40,650 --> 00:19:42,960
IP one for input one.

230
00:19:44,070 --> 00:19:47,220
But I might just call this like problem one or something.

231
00:19:48,260 --> 00:19:49,250
For the output file.

232
00:19:49,820 --> 00:19:53,400
So let's just double check that we have everything, so we have a chance here.

233
00:19:53,430 --> 00:19:57,620
It looks like they get read in after we print.

234
00:19:57,710 --> 00:20:04,910
So get in right here after we print out this little problem to the user and then what we do is we check

235
00:20:04,910 --> 00:20:07,940
each one for all of these four conditions right now.

236
00:20:08,180 --> 00:20:11,720
See one to I want you want to see two.

237
00:20:11,750 --> 00:20:13,700
I want you to try to.

238
00:20:16,090 --> 00:20:16,370
Cool.

239
00:20:16,390 --> 00:20:19,390
So let's go ahead and run this and.

240
00:20:21,190 --> 00:20:24,520
We'll see see if it works.

241
00:20:25,100 --> 00:20:36,100
So I'm going to go ahead and save this and then I'm going to compile it and we'll stay in touch, practice

242
00:20:36,100 --> 00:20:42,910
one copy and I'll say, Oh, and I'm actually going to call this problem one that you see.

243
00:20:47,310 --> 00:20:56,580
So it looks like that compiles, OK, so I'm going to go ahead and run it, so I will see what I can

244
00:20:56,580 --> 00:21:01,270
see, I will say problem one easy.

245
00:21:03,750 --> 00:21:04,060
All right.

246
00:21:04,080 --> 00:21:08,090
OK, yeah, we put it in line there, so immediately, I'm going to want to get rid of that.

247
00:21:08,100 --> 00:21:11,610
I don't want this in line because that doesn't match the output here.

248
00:21:12,390 --> 00:21:13,950
We entered on the same line.

249
00:21:14,760 --> 00:21:22,860
So I'm going to go ahead and remove this and save it and we compile it.

250
00:21:27,410 --> 00:21:28,550
And run that again.

251
00:21:29,480 --> 00:21:38,570
So let's go ahead and check some of the output that we see here, so we have a B 98 to 80 98.

252
00:21:40,880 --> 00:21:44,540
So this says B has a decimal value matching ninety eight.

253
00:21:47,610 --> 00:21:48,510
So pretty cool.

254
00:21:50,750 --> 00:21:51,950
That seems to match the output.

255
00:21:51,980 --> 00:21:54,020
Let's go ahead and try this next one seed.

256
00:21:54,250 --> 00:21:55,310
Thirty twenty two,

257
00:21:58,730 --> 00:22:06,020
fifty three point two So that's no match in characters and integers, so that looks pretty good.

258
00:22:06,470 --> 00:22:13,850
Then we have this capital M Capital L seventy seven point ninety nine Capital and capital.

259
00:22:14,180 --> 00:22:15,590
Thirty seven ninety nine.

260
00:22:16,520 --> 00:22:16,870
Oops.

261
00:22:17,180 --> 00:22:18,070
I didn't write it again.

262
00:22:18,080 --> 00:22:18,380
Huh?

263
00:22:23,450 --> 00:22:27,120
OK, so that seems to mesh him, has a decimal value match in 77.

264
00:22:27,140 --> 00:22:31,760
Now let's try both of them because that's not represented here, but we should have another test case

265
00:22:31,760 --> 00:22:33,140
to see that both of them match.

266
00:22:34,070 --> 00:22:37,880
So that would be, let's see, enmeshed.

267
00:22:37,880 --> 00:22:38,630
77.

268
00:22:38,630 --> 00:22:42,770
So we should use like maybe M and B.

269
00:22:43,870 --> 00:22:45,220
Well, we can even flip those two.

270
00:22:45,250 --> 00:22:48,760
I'll do B and then capital M and then I'll do a.

271
00:22:51,990 --> 00:22:54,540
Seventy seven and ninety eight.

272
00:22:57,960 --> 00:23:01,380
So be in seventy seven, ninety eight.

273
00:23:02,910 --> 00:23:08,790
So get both of those printing out now we have B has a decimal value matching ninety eight and M has

274
00:23:08,790 --> 00:23:11,590
a decimal value matching seventy seven.

275
00:23:12,600 --> 00:23:16,770
So it would be good to check more test cases on this.

276
00:23:16,950 --> 00:23:22,770
So, you know, not just up here to be as thorough as possible, you should check a lot.

277
00:23:24,090 --> 00:23:30,120
It seems like it's working, so it should be working if you're able to pass these tests, but you should

278
00:23:30,120 --> 00:23:32,460
bring up an ASCII table online.

279
00:23:32,460 --> 00:23:41,640
So just search AC iSpace table and go ahead and try some extra input where you look at the decimal values

280
00:23:41,640 --> 00:23:45,510
for a character and then you can go ahead and test them out here.

281
00:23:45,810 --> 00:23:47,280
When you enter the user input.

282
00:23:49,030 --> 00:23:55,510
OK, so hopefully you're able to figure it out if you didn't do it the same way as me, then that's

283
00:23:55,510 --> 00:23:56,860
not a problem at all.

284
00:23:57,550 --> 00:24:03,610
You might have found a more efficient, better way to do this, and that's great.

285
00:24:04,240 --> 00:24:08,560
Honestly, probably a decent amount, and you probably found a better way to do this without having

286
00:24:08,560 --> 00:24:13,740
so much code, which you know that that's great if you did so.

287
00:24:15,580 --> 00:24:19,030
So let's go ahead and move on to the next problem.

288
00:24:22,010 --> 00:24:28,760
So this one is reading into an array.

289
00:24:28,940 --> 00:24:36,140
So this involves user input strings, arrays, conditionals and output.

290
00:24:38,150 --> 00:24:43,940
So this is something you may not have done before, but we need to make a program that reads in three

291
00:24:43,940 --> 00:24:46,190
characters to an array.

292
00:24:47,440 --> 00:24:48,370
Pretty interesting.

293
00:24:49,000 --> 00:24:55,330
So this program should have a hard coded string password variable that you create.

294
00:24:56,310 --> 00:24:59,190
So the length of that password should be three.

295
00:24:59,370 --> 00:25:04,290
So you're basically going to make up your own password, but it has to be three characters.

296
00:25:05,490 --> 00:25:11,310
So once you've read all three characters from the user input into each position of the array.

297
00:25:12,330 --> 00:25:16,290
You'll compare each one of the characters in the array to the string.

298
00:25:17,260 --> 00:25:22,660
So this is kind of asking the question, does each character in the array at a given position match

299
00:25:22,660 --> 00:25:25,150
the character in the string at the same position?

300
00:25:25,780 --> 00:25:29,890
So this is going to involve indexing both arrays and strings.

301
00:25:32,850 --> 00:25:35,730
So if there is a match, then.

302
00:25:38,020 --> 00:25:42,910
So this they then I think if there's a match, then print that out to the console that there was a match

303
00:25:42,910 --> 00:25:44,280
as well as the password.

304
00:25:44,290 --> 00:25:45,730
So you see some examples here.

305
00:25:47,880 --> 00:25:50,730
You know, here's this like wrong, guess wrong, guess?

306
00:25:50,880 --> 00:25:54,520
But then when it was guessed correctly, it says you guessed the password.

307
00:25:54,540 --> 00:25:56,220
Password equals yes.

308
00:25:56,240 --> 00:26:01,470
In this example, so says the message that first displays is enter the three letter password.

309
00:26:01,470 --> 00:26:04,410
Then you type a guess as the user.

310
00:26:06,420 --> 00:26:11,490
And then you can say, you guessed the password, if it's correct, otherwise you say wrong guess,

311
00:26:11,760 --> 00:26:15,900
and you'll say you guessed the password and then a period and then you'll say password equals and then

312
00:26:15,900 --> 00:26:17,040
whatever the user entered.

313
00:26:19,460 --> 00:26:26,480
OK, so go ahead and pause the video if you like to try this on your own, which you really should.

314
00:26:26,990 --> 00:26:28,670
I'm sure you can figure this out.

315
00:26:28,910 --> 00:26:36,810
I know that we haven't gone over reading into an array, but I think you can figure it out.

316
00:26:36,830 --> 00:26:38,450
I'm just kind of challenging you here.

317
00:26:39,260 --> 00:26:42,160
You do know how to index an array.

318
00:26:42,170 --> 00:26:49,100
So if you're trying to read into a specific position in an array, just think about how you use that

319
00:26:49,100 --> 00:26:51,530
index and how you you see in.

320
00:26:53,990 --> 00:26:54,530
All right.

321
00:26:54,740 --> 00:26:58,130
So I'm going to go ahead and try and solve this here.

322
00:27:00,590 --> 00:27:04,910
So I'm going to actually make a new file here.

323
00:27:06,910 --> 00:27:11,860
So I do find new files, language, C++ and.

324
00:27:13,100 --> 00:27:20,080
Let's see, I'll just start out, I know I'm going to print stuff out, so I'll include extreme may

325
00:27:21,650 --> 00:27:23,430
include namespaces me.

326
00:27:28,180 --> 00:27:37,730
I want that in their main function going, Yeah, let me go ahead and just save this right away.

327
00:27:39,710 --> 00:27:47,460
I think I'm just going to call this problem to keep.

328
00:27:48,810 --> 00:27:49,200
Cool.

329
00:27:49,710 --> 00:27:50,250
So.

330
00:27:52,020 --> 00:27:53,550
Let's go ahead and.

331
00:27:55,510 --> 00:27:58,040
I have the terminal here as well.

332
00:27:59,950 --> 00:28:00,860
Want to clear that?

333
00:28:03,090 --> 00:28:09,150
So let's go ahead and break down this problem, so make a program that reads three characters into an

334
00:28:09,150 --> 00:28:09,630
array.

335
00:28:10,050 --> 00:28:18,210
So we would maybe be thinking that we're going to need some variables to read into, but it doesn't

336
00:28:18,210 --> 00:28:20,280
say to read it into variables.

337
00:28:20,280 --> 00:28:22,350
It says to read it into an array.

338
00:28:22,350 --> 00:28:27,000
So I know for sure I'm I need an array, so I'm going to go ahead and do that.

339
00:28:27,840 --> 00:28:29,340
So I'm just going to call this.

340
00:28:29,340 --> 00:28:31,530
It's going to be an array of characters, right?

341
00:28:31,530 --> 00:28:33,840
Because we're reading in characters three of them.

342
00:28:34,740 --> 00:28:35,340
So.

343
00:28:37,660 --> 00:28:43,570
What I can do is I'm going to I'm just going to call this a RR just for array.

344
00:28:43,600 --> 00:28:46,900
You can call it wherever you want, and it's going to be size three.

345
00:28:48,400 --> 00:28:50,740
So I'm just going to declare my array like that.

346
00:28:52,990 --> 00:28:58,620
So then it says to read into it, so you're probably like wondering, how do I do that?

347
00:28:58,760 --> 00:29:00,310
I got to read it into array.

348
00:29:00,340 --> 00:29:04,000
I read it into a variable form, but I don't know how to read into array.

349
00:29:04,450 --> 00:29:06,670
Well, very similar thing.

350
00:29:06,880 --> 00:29:11,290
So promise if you were able to figure this out on your own, if not totally fine.

351
00:29:13,000 --> 00:29:18,490
But rather than like, let's just say you have something to write, you would just be like seeing into

352
00:29:18,490 --> 00:29:18,910
a.

353
00:29:20,800 --> 00:29:27,670
But if you got to read into the array, you have three different positions that you want to put the

354
00:29:27,670 --> 00:29:28,840
characters at, right?

355
00:29:29,680 --> 00:29:31,270
So what's the first position?

356
00:29:31,930 --> 00:29:36,430
The first position is indexed like this write array is zero.

357
00:29:37,240 --> 00:29:40,360
So all you have to do is see into that.

358
00:29:40,360 --> 00:29:55,450
So see into a R zero and then see into a R one and so on with one and then air two.

359
00:29:56,410 --> 00:30:05,560
So just like that, just like reading into a variable, you read into the array because the array has

360
00:30:05,560 --> 00:30:08,440
three slots, right?

361
00:30:09,340 --> 00:30:17,440
So since we're entering three characters you can read, read into these three slots here.

362
00:30:19,390 --> 00:30:24,190
So, you know, remember that it starts out at zero, the first position is zero in computer science,

363
00:30:24,190 --> 00:30:26,220
we're starting with that index zero.

364
00:30:26,230 --> 00:30:30,340
Most of the time, there are some programming languages that start at one.

365
00:30:30,820 --> 00:30:35,200
I'm not going to talk about those, but most programming languages are starting with the index zero.

366
00:30:37,220 --> 00:30:43,100
So we read into the first position of the era with that first character that the user would enter,

367
00:30:43,580 --> 00:30:50,930
then the second position of the array is a second character and then this is the third position of the

368
00:30:50,930 --> 00:30:52,710
era right since we started here.

369
00:30:52,730 --> 00:30:54,080
These are all offset by one.

370
00:30:54,080 --> 00:30:54,830
They're one less.

371
00:30:55,670 --> 00:30:58,940
Before we read in, though, we're going to have to put out a little message, right?

372
00:30:59,660 --> 00:31:03,260
So the message says, enter the three-letter password.

373
00:31:06,050 --> 00:31:10,670
So let's go ahead and check that out then.

374
00:31:12,260 --> 00:31:20,930
So I'm going to go ahead and push out and enter, say nothing without a password.

375
00:31:21,080 --> 00:31:26,870
The three letter password, yeah, the three letter password.

376
00:31:30,190 --> 00:31:33,220
And we want it on the same line.

377
00:31:35,050 --> 00:31:36,730
So I'm not going to put it in line there.

378
00:31:40,200 --> 00:31:43,560
Cool, so we go ahead and read that in.

379
00:31:45,450 --> 00:31:48,030
And then what needs to happen, let's go back to our problem description.

380
00:31:50,210 --> 00:31:54,950
So once you have read all three characters and the user input into each position of the array, compare

381
00:31:54,950 --> 00:31:59,210
each one of the characters in the array to the extreme, so we haven't made that string yet, right?

382
00:31:59,540 --> 00:32:03,590
This program should have a hard coded string password variable that you create.

383
00:32:03,890 --> 00:32:05,750
So let's go ahead and create that variable.

384
00:32:06,770 --> 00:32:13,310
So we have the array here, and I'm going to go ahead and create a string, and I'm going to call this

385
00:32:13,310 --> 00:32:15,110
string password.

386
00:32:17,240 --> 00:32:19,010
And just say equals.

387
00:32:19,430 --> 00:32:24,350
And in this example, I'll just put, you know, I had that in that example.

388
00:32:24,680 --> 00:32:27,230
Yes, I thought it was something else, though.

389
00:32:30,160 --> 00:32:32,790
We could just say one.

390
00:32:33,070 --> 00:32:34,000
Something like that.

391
00:32:34,390 --> 00:32:34,900
I don't know.

392
00:32:35,260 --> 00:32:36,520
Pretty weak password, right?

393
00:32:39,540 --> 00:32:44,610
So once you read all three characters and the user input in each position and the array, we've done

394
00:32:44,610 --> 00:32:45,450
that right.

395
00:32:45,600 --> 00:32:51,510
So now we need to compare each one of the characters in the array to the string.

396
00:32:52,830 --> 00:32:59,400
So how do we do that if we're comparing them that is similar to like this previous problem, right?

397
00:33:00,420 --> 00:33:01,110
So.

398
00:33:02,530 --> 00:33:03,460
And actually, I'm going to.

399
00:33:04,490 --> 00:33:07,970
Let's just present this to you, because I haven't had it right all the way up.

400
00:33:10,240 --> 00:33:14,830
So this previous one, we were comparing Char and in.

401
00:33:14,860 --> 00:33:19,630
Right, so we're doing another comparison here, which implies that we should probably use some more

402
00:33:19,630 --> 00:33:20,700
conditional, right?

403
00:33:21,880 --> 00:33:23,940
So let's go ahead and do that.

404
00:33:26,840 --> 00:33:33,320
So I'm going to start out with another if and what I need to do is I need to compare.

405
00:33:34,560 --> 00:33:42,240
Each array position, so like this, for example, in this in this, these are the three array positions,

406
00:33:42,240 --> 00:33:43,740
and then we have three.

407
00:33:44,920 --> 00:33:47,290
Positions of the string, right?

408
00:33:47,860 --> 00:33:57,640
So we have one, two, three or more appropriately, zero one to remember how we actually were able

409
00:33:57,640 --> 00:33:59,470
to index strings as well.

410
00:34:00,160 --> 00:34:04,570
So we're going to compare our array indices to our string indices.

411
00:34:04,570 --> 00:34:10,120
So this will be like a zero needs to be compared to this one right there.

412
00:34:10,600 --> 00:34:10,920
All right.

413
00:34:10,990 --> 00:34:13,750
One needs to be compared to this one right here.

414
00:34:14,190 --> 00:34:16,660
Array two needs to be compared to this one right here.

415
00:34:17,260 --> 00:34:19,960
Of course, since we know our password is.

416
00:34:21,380 --> 00:34:28,430
The word one we could just compare directly to a character like a hard coded character like this, like

417
00:34:28,940 --> 00:34:34,340
if Air Zero is equal to uh oh.

418
00:34:34,910 --> 00:34:38,720
But the problem specifically says that.

419
00:34:42,310 --> 00:34:46,660
Compared to one of the characters in the array to the string, so actually doesn't say to index the

420
00:34:46,660 --> 00:34:48,370
string, but I think that.

421
00:34:51,060 --> 00:34:55,650
It says right here, you know, does each character in the ring at a given position match the character

422
00:34:55,650 --> 00:34:57,390
in the string at the same position?

423
00:34:58,080 --> 00:35:03,420
So I feel like that kind of implies that we should index the string as well.

424
00:35:03,420 --> 00:35:08,710
So in that way, if we wanted to do this, we wouldn't have to change our logic later, right?

425
00:35:08,730 --> 00:35:14,790
Let's say we want to change the password to something else, then we don't have to go and change our

426
00:35:14,790 --> 00:35:17,900
if statements are conditional statements.

427
00:35:21,680 --> 00:35:25,490
You know, we don't have to come change our statement, if you know, however many are, if we have

428
00:35:25,490 --> 00:35:25,880
one.

429
00:35:26,210 --> 00:35:28,070
I'm not sure yet how many of you have.

430
00:35:28,700 --> 00:35:32,870
We would only have to change the string if we use the string indexing.

431
00:35:35,040 --> 00:35:44,910
So let's think about this, we need to for sure do this air zero equals equals and then we'll do password

432
00:35:45,870 --> 00:35:48,900
zero like this that way.

433
00:35:49,140 --> 00:35:57,030
This is just saying the first thing in the array is equal to the first thing in this password string.

434
00:35:59,720 --> 00:36:02,690
So that's this will check the first thing.

435
00:36:02,900 --> 00:36:04,360
So what do we do for the rest?

436
00:36:04,370 --> 00:36:06,740
Do we make additional if statements?

437
00:36:06,770 --> 00:36:09,010
Well, we we can.

438
00:36:09,020 --> 00:36:15,800
But we also could just put it all in one if statement because we only care if everything matches right.

439
00:36:16,490 --> 00:36:21,380
So we could say is if this first thing matches and.

440
00:36:21,840 --> 00:36:25,250
And then I can just copy paste this.

441
00:36:28,670 --> 00:36:33,500
And I can say, OK, not only the first thing, but the second thing matches, too.

442
00:36:34,580 --> 00:36:38,450
And and then I'll copy paste again and I'll say and the third.

443
00:36:40,420 --> 00:36:42,640
Position matches as well.

444
00:36:43,570 --> 00:36:51,070
So this is if all three positions are matching, then we can print out.

445
00:36:53,190 --> 00:36:56,050
That you guessed the password.

446
00:36:56,100 --> 00:36:58,980
Password equals and whatever the password is, right?

447
00:37:01,770 --> 00:37:06,210
So I will say you guessed the password.

448
00:37:09,240 --> 00:37:17,910
Password equals and then right here I will just say password to variable.

449
00:37:18,990 --> 00:37:19,290
All right.

450
00:37:22,050 --> 00:37:22,950
Put it in line there.

451
00:37:25,370 --> 00:37:32,420
So that'll print out the actual password and, you know, this text that was matching what was on the

452
00:37:32,420 --> 00:37:33,140
output here.

453
00:37:35,230 --> 00:37:38,920
So what if it doesn't match, though, then what do we print out?

454
00:37:39,430 --> 00:37:42,550
So if it doesn't match, it just says wrong, guess?

455
00:37:43,760 --> 00:37:51,590
So let's go ahead and handle that, so the case in which it doesn't match is basically when all of this

456
00:37:51,590 --> 00:37:52,450
is false, right?

457
00:37:53,360 --> 00:37:56,570
It just really if any one of these is false, actually.

458
00:37:56,990 --> 00:38:01,170
So this is saying, you know, each position has to be true.

459
00:38:01,190 --> 00:38:08,210
The first one and second position has to match and third position estimates.

460
00:38:10,060 --> 00:38:15,760
If this is false, if this whole statement evaluates to false, that means that the passwords don't

461
00:38:15,760 --> 00:38:16,630
completely match.

462
00:38:16,630 --> 00:38:23,290
So that means that I could put an else here and then I can put that I could put wrong guess.

463
00:38:27,910 --> 00:38:28,750
So foot wrong.

464
00:38:28,780 --> 00:38:29,170
Yes.

465
00:38:30,370 --> 00:38:33,870
And up in the line, I cannot Typekit in line correctly.

466
00:38:34,040 --> 00:38:34,600
Let me.

467
00:38:36,870 --> 00:38:40,530
OK, so that seems to pretty much cover it.

468
00:38:40,560 --> 00:38:43,650
Let's go ahead and save this and test it out.

469
00:38:45,970 --> 00:38:51,400
So I went ahead and say that I'm going to compile it now, so I'll save problem to

470
00:38:53,830 --> 00:38:56,800
copy that and I'll call this.

471
00:38:57,550 --> 00:38:59,440
I want to see.

472
00:39:01,480 --> 00:39:01,860
OK.

473
00:39:01,910 --> 00:39:06,760
Comp. All right, so let's go ahead and test this out

474
00:39:11,200 --> 00:39:12,130
to see.

475
00:39:13,390 --> 00:39:15,310
So let's go ahead and enter.

476
00:39:15,340 --> 00:39:17,080
Let's enter the wrong password first.

477
00:39:17,080 --> 00:39:27,010
So I'll just say to the wrong guests and then I will go ahead and say.

478
00:39:32,280 --> 00:39:33,690
Yes, yes, I would say one.

479
00:39:34,380 --> 00:39:36,360
Yes, the password password equals one.

480
00:39:38,230 --> 00:39:38,620
Cool.

481
00:39:38,980 --> 00:39:42,130
So seems to seems to work.

482
00:39:42,580 --> 00:39:43,780
This program is.

483
00:39:46,450 --> 00:39:51,520
You know, kind of not the best is as far as taking input because.

484
00:39:52,880 --> 00:40:01,520
You know, it doesn't really check to see how long things are like, for example, if I was to run this

485
00:40:01,520 --> 00:40:08,930
and I said like the password is password or something like that, says Ron Guess.

486
00:40:09,800 --> 00:40:15,650
But you know, I'm entering extra stuff, which it probably should have a message that says, like,

487
00:40:15,980 --> 00:40:21,950
you haven't entered a password of of length three.

488
00:40:22,640 --> 00:40:27,380
So but you know, we're just kind of doing a basic program now.

489
00:40:27,380 --> 00:40:29,030
So, you know, it still works.

490
00:40:29,810 --> 00:40:31,160
It says wrong, guess.

491
00:40:31,670 --> 00:40:39,410
But something we need to look into the into in the future is to see how, you know, checking for how

492
00:40:39,410 --> 00:40:45,770
long things are that are entered, checking to make sure people entered the right format of something.

493
00:40:48,760 --> 00:40:53,890
You know, there could be like some sort of seeing fail.

494
00:40:55,090 --> 00:41:01,360
If I were to run this and I just put like, let's see, it's taking in charge, so I don't really know

495
00:41:01,360 --> 00:41:04,240
how I would be able to make it to to fail.

496
00:41:04,250 --> 00:41:09,840
But let's say that we are taking in integers, you know, and then I entered like a b c.

497
00:41:10,750 --> 00:41:11,830
That would be a problem, right?

498
00:41:11,830 --> 00:41:14,620
If I was reading into three integers, we already went over that.

499
00:41:15,340 --> 00:41:20,950
So it would be good if we had some kind of mechanism to check what was going on in the input, rather

500
00:41:20,950 --> 00:41:22,900
than just only match it to our password.

501
00:41:25,510 --> 00:41:29,260
But, you know, it still works, still works pretty well.

502
00:41:30,070 --> 00:41:36,610
So if you figure this out, definitely props to you and good job, if not, no big deal, you know?

503
00:41:37,000 --> 00:41:40,870
I didn't go over how to read into positions in an array.

504
00:41:41,140 --> 00:41:45,850
I was just trying to challenge you to see if you could maybe potentially figure it out.

505
00:41:46,480 --> 00:41:50,880
If you had to look up stuff that's totally fine looking up stuff is definitely what you should do.

506
00:41:50,890 --> 00:41:52,570
That's what most programmers do.

507
00:41:52,900 --> 00:41:58,600
If you think that people just automatically write code without having to look stuff up and google it,

508
00:41:59,440 --> 00:42:06,010
you would be greatly mistaken because programmers job is pretty much 90 percent Googling anyways.

509
00:42:06,010 --> 00:42:09,340
So yeah, don't worry about looking stuff up.

510
00:42:12,100 --> 00:42:16,120
So, yeah, we ran into each one of these positions that was kind of the new thing.

511
00:42:16,330 --> 00:42:24,610
And then we used a conditional statement here, just one f where we combined each one of these statements,

512
00:42:24,610 --> 00:42:31,300
these checks with the and operator logical and right here.

513
00:42:33,460 --> 00:42:36,670
Cool, so I only have these two problems.

514
00:42:38,320 --> 00:42:44,660
For this lecture after this, we're going to get into some other ways to take in input.

515
00:42:45,550 --> 00:42:48,600
We will be looking at reading in a line of input.

516
00:42:48,610 --> 00:42:55,570
I think I already kind of foreshadowed that in the last lecture I talked about that, but we'll look

517
00:42:55,570 --> 00:43:00,410
into reading into strings as well, not only reading into the primitive types.

518
00:43:01,510 --> 00:43:08,350
For example, if we were to read this into a string, we could check it as well, and we could also

519
00:43:08,350 --> 00:43:12,880
check the length with like password length.

520
00:43:13,590 --> 00:43:13,930
Right?

521
00:43:14,800 --> 00:43:20,470
So that's something cool that we will do in the upcoming lectures.

522
00:43:21,160 --> 00:43:23,740
OK, so with that, I will see you in the next lectures.
