Forum » Programiranje » napaka c++
napaka c++
![](https://static.slo-tech.com/stili/avatar_gray.gif)
kretze ::
Zdravo folk kaj ve kdo zakaj mi v tem programu takoj ko ugotovim eno črko izpiše celo besedo in ne ko ugotovim vseh 5?? pa hvala vsem za odgovore
/* Ime in priimek: #include <iostream> #include <string> #include<cstlib> using namespace std; int main() { string origword; string leter; char dashreplaced = 'N'; int numIncorect = 0; char gameOver = 'N'; string displayword = "_ _ _ _ _"; while (origword.length() != 5) { cout << "enter 5-leter word in upercase "; getline(cin, origword); } system("cls"); cout << "guest this word " << displayword << endl; while (gameOver == 'N') { cout << "enter a upercase letter "; cin >> leter; for (int i = 0; i < 5; i++) { if (origword.substr(i, 1) == leter) { displayword.replace(i, 1, leter); dashreplaced = 'Y'; } } if (dashreplaced == 'Y') { if (displayword.find("-", 0) == -1) { gameOver = 'Y'; cout << endl << "yes the word is " << origword << endl; cout << "great guesing " << endl; } else { cout << endl << "guess this word " << displayword << endl; dashreplaced = 'N'; } } else { numIncorect++; if (numIncorect == 10) { gameOver = 'Y'; cout << endl << "sory the word is " << origword << endl; } } } system("pause"); return 0; }
![](https://static.slo-tech.com/stili/bel_rudis.png)
AndrejS ::
string displayword = "_ _ _ _ _"; in if (displayword.find("-", 0) == -1) ne gre najbolj skupaj
Tak na hitro pogledano "_" != "-"
Tak na hitro pogledano "_" != "-"
Vredno ogleda ...
Tema | Ogledi | Zadnje sporočilo | |
---|---|---|---|
Tema | Ogledi | Zadnje sporočilo | |
» | [C] Sinhronizacija procesovOddelek: Programiranje | 1162 (1035) | Cvenemir |
» | [C] struct in int[] (strani: 1 2 )Oddelek: Programiranje | 7517 (6590) | MrBrdo |
» | C osnovaOddelek: Programiranje | 1571 (1086) | RunoTheDog |
» | win api (c++)Oddelek: Programiranje | 2575 (1855) | Gundolf |
» | int to string v c++Oddelek: Programiranje | 2358 (2086) | OwcA |