» »

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 "_" != "-"


Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo
»

[C] Sinhronizacija procesov

Oddelek: Programiranje
71146 (1019) Cvenemir
»

[C] struct in int[] (strani: 1 2 )

Oddelek: Programiranje
657380 (6453) MrBrdo
»

C osnova

Oddelek: Programiranje
221559 (1074) RunoTheDog
»

win api (c++)

Oddelek: Programiranje
462551 (1831) Gundolf
»

int to string v c++

Oddelek: Programiranje
272341 (2069) OwcA

Več podobnih tem