Ch 3 Hangman
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
|
#include <iostream>
#include <string>
using namespace std;
int main()
{
char ch;
string solution;
string list[] = { "the", "cat", "programming", "language", };
int n = rand() % 4;
solution = list[n];
string guess(solution.length(), '_');
while (true)
{
cout << guess << endl;
cout << "Type letter: ";
cin >> ch;
for (int i = 0; i < solution.length(); i++)
{
if (ch == solution[i])
{
guess[i] = ch;
}
}
if (solution == guess)
{
cout << solution << endl;
cout << "Success!";
break;
}
}
return 0;
}
|
cs |
length 함수: 문자열의 길이를 구함.
ex.
string variable = "happy";
cout << variable.length();
결과값: 5
'⭐ Programming > C++' 카테고리의 다른 글
Pseudo code : Bull Cow Cartridge (0) | 2022.03.10 |
---|---|
Pre-Increment/Decrement, Post-Increment/Decrement (0) | 2022.03.10 |
Visual Studio Code 단축키 (0) | 2022.03.10 |
Ch 4.7 CircleRun (0) | 2022.03.09 |
Ch 4.6 Class (0) | 2022.03.08 |
댓글
이 글 공유하기
다른 글
-
Pre-Increment/Decrement, Post-Increment/Decrement
Pre-Increment/Decrement, Post-Increment/Decrement
2022.03.10 -
Visual Studio Code 단축키
Visual Studio Code 단축키
2022.03.10 -
Ch 4.7 CircleRun
Ch 4.7 CircleRun
2022.03.09 -
Ch 4.6 Class
Ch 4.6 Class
2022.03.08