I hv an assignment to translate words enter by user.
I have done some code and it is work to translate single letter enter by user... e.g: the user enter "suka" will be translate to "like" because in the txt file (i make as a database file and it is linked with cpp file) I already put the word and translated word..so that each time it read the word entered it will output the translated word as provided...
but I having problem in how I can modify the code so that it can translate all words entered. e.g: the user enter "saya suka" that have two words will be output "I like"...currently, it will translate or match the 1st word only...
plz help me how to modify the code so that it will read all word/letter enter by user include with space....
The code as posted above does not compile, so how is it you are able to run? Or are you just saying that you think it will do what you said?
Your first problem is that you only ever read the first word from translation.txt. I assume that the file looks like:
saya I
suka like
If so, you have to read two words from each line and store them in an array such that you can look up the word the user entered and find the corresponding translation. Once you've figured out how to read all the lines in the file, you essentially have what you need to do the second part; you'll just need a loop (that loops until the user wants to quit).
this translation.txt is diferent file from cpp and it is linked.
I hv try to use looping (eg. while / do while) but it failed and the code as follow...
1 2 3 4 5 6 7 8 9 10 11 12 13 14
for (i=0; i<10000; i+=2)
do {
if (!strcmp(str, numbers[i]))
{
cout<< "English word is : \n"<<"================================\n\n\n"<<"\t"<<numbers[i+1]<<" "<<"\n\n\n\n\n";
break;
i+1;
}
}while ( i+=2 && i<10000);
I have no idea to modify this code so that it can read next character input by user....plz help me....thank a lot cause give me a respond .... :)