Hey guys, I am new to programming and have to write a translation program based off of words that were given to us in two text files, an English and Spanish one. Whenever I run the program I have so far it keeps crashing though, any advice?
sorry im not sure how to use code tags, just created my account D:
in each file is a list of 38 words with matching english words in the ENG.txt and the corresponding spanish words in the same order in the SPAN.txt file
BLACK
BLUE
BROWN
GREEN
GOLD
GREY
INDIGO
ORANGE
PINK
PURPLE
RED
SILVER
TURQUOISE
VIOLET
WHITE
YELLOW
ONE
TWO
THREE
FOUR
FIVE
SIX
SEVEN
EIGHT
NINE
TEN
TWENTY
HUNDRED
HELLO
GOODBYE
GOOD
JUNGLE
PARK
SOCCER
BASEBALL
HOCKEY
BASKETBALL
FINISHED
(and then the spanish text file is the same format but in spanish)
oh, it is not running the program that I am having difficulty with, it's getting the program to take the word the user inputs and convert it to the opposite language
I recommend looking at this post to help you out. Translators are only easy if you know what your doing. http://wiki.tcl.tk/10262
It's an added challenge that you are trying to full the words from a text file aswell.
First step: What did you do EXACTLY to make it crash. What did you type and what did you get as output? Why do you say it crashed, what did you expect the output to be?
Second step: What is your code designed to do? Where is your pseudocode?
What is the code between lines 23 to 30 supposed to do? Just in simple pseudocode or 1 or 2 sentences in plain english will do.
Also please explain what the difference is between your two versions that makes them substantially different?
#include <iostream>
#include <string>
usingnamespace std;
int display();
int main()
{
string word;
string ENG[] = {"BLACK","BLUE", "BROWN","GREEN"};
string SPAN[] = {"NERO","AZUL","MARRON","VERDE"};
int length = sizeof(ENG) / sizeof(string);
int lang = display();
switch (lang)
{
case 0:
exit(0);
break;
case 1:
cout << "What word would you like to translate?" << endl;
cin >> word;
for (int i = 0; i < length; i++)
{
if (word == ENG[i])
cout << SPAN[i] << endl;
}
break;
case 2:
cout << "What word would you like to translate?" << endl;
cin >> word;
break;
default:
cout << "Error stuff" << endl;
// sort this out later
}
system("pause");
return 0;
}
int display()
{
int selection = 0;
cout << "What would you like to translate to?\n" << endl;
cout << "1. Spanish" << endl;
cout << "2. English" << endl;
cout << "0. Exit" << endl;
cin >> selection;
return selection;
}
i can see that coe but what you have done isn't what i think that they are trying to accomplish. You are using an array rather than pulling the words from a file. I'm working on efficient code that will pull the text from a file. It's mostly aesthetics for now though.
@jasoncoe
Exactly! You now have to find a way to 'feed' the arrays by delving into the two text files and extracting their contents in an orderly way. But that aspect was talked about many posts ago.
Put the two together and your new beaut translator will sing.