I have to create a game, in which the computer chooses randomly a word out of 5 and randomizes its characters, so that the user has to guess the word. He can also get a hint of the computer. I have started the code, but dont know how to continue:
include <iostream>
include<ctime>
include <string>
include <iostream>
include <ctype.h>
include <cstring>
include <locale>
include <math.h>
include <stdio.h>
include <stdlib.h>
include <time.h>
to random the letters in a word you could take like a number of 10 changes each time the computer picks a word and for example ... 1 change would be :
take 2 rand int between 0 and noofletters-1 and change their places within the word ....
you could do the change like this i think ...
Actually, it's the syntax for how the function has to be used to generate a random number. rand() % 5 gives a random number from 0 to 4 (perhaps from 1 to 5, I don't remember, check the result yourself).
Don't forget you have to initialise the time kernel of rand() with srand( time(NULL) ), so that you get a different random number each time you start the program.
% gives you the remainder after division. (19 % 7 == 5, because 19 / 7 == 2 remainder 5)
When coupled with rand, it effectively gives you a random number between 0 and x-1. So rand() % 5 will give you a random number between 0 and 4, because any number divided by 5 will have a remainder somewhere between 0 and 4.