Forum » Programiranje » napaka c++
napaka c++
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;
}

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 | 1290 (1163) | Cvenemir |
| » | [C] struct in int[] (strani: 1 2 )Oddelek: Programiranje | 8276 (7349) | MrBrdo |
| » | C osnovaOddelek: Programiranje | 1652 (1167) | RunoTheDog |
| » | win api (c++)Oddelek: Programiranje | 2686 (1966) | Gundolf |
| » | int to string v c++Oddelek: Programiranje | 2460 (2188) | OwcA |