EDIT: The real problem was that I was stuck in the while loop
////////////////////////////////////////////
// //
// *Created by MMMMMMMEEEEEE //
// //
////////////////////////////////////////////
#include<iostream.h>
#include<conio.h>
int main()
{
int lifes=0;
char letter;
int nope;
char word[20]={0};
char newword[20]={0};
cout<<"Write a word: ";
cin>>word;
while ( lifes <=5 && newword != word)
{
nope=0;
cout<<endl<<"Guess a letter: ";
cin>>letter;
for(int n=0; n<21; n++) {
if(word[n] == letter) {
word[n]=newword[n];
nope=1; } }
if(nope<1) {
lifes=lifes+1;
cout<<"Sorry please try again."<<endl; }
}
if (lifes>5) {
cout<<endl<<"You lose"; }
else if (newword == word) {
cout<<endl<<"You win!"; }
getch();
return 0;
}
Sorry that my structure isn't very nice.
/\/\/\/\/\/\/\/\/\ EDIT: Thanks for all the help!! It works! /\/\/\/\/\/\/\/\/\
////////////////////////////////////////////
// //
// *Created by MMMMMMMEEEEEE //
// //
////////////////////////////////////////////
#include<iostream.h>
#include<conio.h>
int main()
{
int lifes=0;
char letter;
int nope;
char word[20]={0};
char newword[20]={0};
cout<<"Write a word: ";
cin>>word;
while ( lifes <=5 && strcmp(newword, word) != 0)
{
nope=0;
cout<<endl<<"Guess a letter: ";
cin>>letter;
for(int n=0; n<20; n++) {
if(word[n] == letter) {
newword[n]=word[n];
nope=1; } }
if(nope<1) {
lifes=lifes+1;
cout<<"Sorry please try again."<<endl; }
}
if (lifes>5) {
cout<<endl<<"You lose"; }
else {
cout<<endl<<"You win!"; }
getch();
return 0;
}
This post has been edited by protomanv9: 20 January 2010 - 09:36 PM

New Topic/Question
Reply





MultiQuote





|