944,137 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 240
  • C++ RSS
Oct 27th, 2009
0

please help to debug this

Expand Post »
Please can anyone out there help me see the problem with this piece of code? I’ve tried running it on the visual studio compiler
But either get warnings or undesired output.
I supposed the code to be a little dictionary that compares
Inputs with some set of predefined ones and then output
It’s meaning if matches are found. Otherwise print NOT FOUND
And ask user to research.
Here’s the snippet:

C++ Syntax (Toggle Plain Text)
  1.  
  2. #include <iostream>
  3. #include <string>
  4. #include <vector>
  5. using namespace std;
  6.  
  7.  
  8. int main()
  9. {
  10. bool chance = true;
  11. char *Dictionary[][2] ={
  12. "God", "osalobua",
  13. "welcome", "obokhian",
  14. "jesus", "ijesu christy",
  15. "come", "lare",
  16. "friend", "ose",
  17. "school", "Esuku",
  18. "go", "kpa",
  19. "sun", "oven",
  20. "man", "okpia",
  21. "woman", "okhuo",
  22. "child", "omo",
  23. "baby", "omomo"
  24.  
  25. };
  26.  
  27. while(chance)
  28. {
  29. int i;
  30. char word[20];
  31. cout << "Enter a word and i'll tell\n"
  32. <<"you about it in edo language: ";
  33. cin >> word;
  34.  
  35. for(i = 0; *Dictionary[i][0]; i++){
  36. if(!strcmp(Dictionary[i][0], word)){
  37. cout <<"\n"<<word <<" is translated"
  38. <<" as => " <<Dictionary[i][1]
  39. <<" \nin edo language ";
  40. break;
  41. }
  42. }
  43. if(!*Dictionary[i][0]){
  44. cout <<"sorry! there's no matching word like"<<word;
  45. cout <<"will you like to search again?(y or n)";
  46. string restart;
  47. cin>>restart;
  48. if(restart != "y")
  49. chance = false;
  50. }
  51. }
  52.  
  53. return 0;
  54. }

here's the warning message from the compiler:

1>LINK : warning LNK4076: invalid incremental status file 'G:\arraysnd veators\Debug\arraysnd veators.ilk'; linking nonincrementally
1>Embedding manifest...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.0.5724.0
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>LINK : warning LNK4076: invalid incremental status file 'G:\arraysnd veators\Debug\arraysnd veators.ilk'; linking nonincrementally
1>Build log was saved at "file://g:\arraysnd veators\arraysnd veators\Debug\BuildLog.htm"
1>arraysnd veators - 0 error(s), 2 warning(s)
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
osgiedeprof is offline Offline
4 posts
since Oct 2009
Oct 28th, 2009
0
Re: please help to debug this
You use the STL string class later in your program so why not use it here, too:
string Dictionary[12][2] ={ {"God", "osalobua"}, etc
and here:
string word;

Line 35 could then be:
for(i = 0; i < 12; ++i)

and Line 36 is simply
if(word == Dictionary[i][0])

with line 41 being :
if(i == 12)

You never use a vector, so why include the vector header?
Reputation Points: 718
Solved Threads: 373
Nearly a Posting Maven
Lerner is offline Offline
2,253 posts
since Jul 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: infinite while loop
Next Thread in C++ Forum Timeline: how to determine the size of the dynamic array





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC