hi..

i'm trying to creat a game on c++ that store some words with at least seven letters in an array, and to randomly select one word and jumble up the letters and display the jumbled-up word.

like..

PROJECT can be jumbled-up as CJEROTP

The player has to guess the correct word.
The player will type the letters in a correct order to form the word.
and they must try until they get the right word
and give the option to continue

i'v been working on it for some time...but it seems that i'm missing something...:-/

thx

but it seems that i'm missing something

Umm, like maybe the code? My crystal ball is out for a tuneup right now.

Please post your code, or pertinent portion of it, and try to describe what particular problem you're having. No one here is going to write the program for you.

this is my first time to write in a form for help..
i don't know how things work here..

anyway..

i'm still new to c++...so i looked in alot of websites for some clues..so maybe it's messed up and dosen't make much sence ^_^"

i don't know how to randomly select one word and jumble up the letters and display the jumbled-up word for the player.

------------
#include <stdio.h>
#include <cstdlib>

int main()
{
char name;
char answer;
char again;

do
{

srand ( time(0) );
readNameFile(names, "names.txt");


do
{

printf("what is this word? %s\n",names);
scanf("%s",&answer);

if(answer!=name)
{
printf("ur answer is wrong.try arain!!\n\n");
continue;
}
else if (answer==name)
printf("the answer is right \n\n");
break;
}
}
while (i<4)
printf("would u like to continue? (y\n):");

scanf("%c",&again);
while (again=='y');
return 0;
}

Since you're new here and don't know how things work, it would be a good start to read the sticky threads at the top of this forum, especially this one

Please post your code inside the tags

[code]

your code goes here

[/code]

That said, lets look at a few of things that need attention in your program.

Variables name and answer - you declare them as char (single character), but treat them as strings (array of char) in the code. Also, do you mean to use name or names?

Where's the readNameFile function? Does it return some indicator of success? You cannot depend on it always being able to open and read the file -things can go wrong.

Given that you will correct your variable declarations to be strings, you cannot compare two C-style strings with the == operator. You must use a string comparison function.

Try to make your loop control completely based on the while condition. Use of break and continue in the loop are not the most elegant approach. Perhaps a variable that indicates correct guess or not.

This is C++ forum - why don't you use the C++ input and output methods. If you're really going to just do C, there's a forum for that.

That should keep you busy a while.

thanks vmanes for ur help and pointing out the mistakes..
i'll work on them and i'll take by ur advice

sorry for the truble

sorry for the truble

Nothing to be sorry for, you're looking for help, and that's what we do here.

Just choose an index randomly and swap( i ,lengh-i+1) position

swap(i, length - (i + 1) )

But don't forget the brackets, because you would get some very funny results, especially with index 0 and 1. :)

This article has been dead for over six months. Start a new discussion instead.