Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 21st, 2016, 11:14 AM   #1
Smjprogrammer
Learning Very Basic Stuff
 
Smjprogrammer's Avatar
 
Join Date: Jan 2010
Location: United States
Posts: 978
Rep Power: 8 Smjprogrammer is on a distinguished road
Need Help With Hangman

I was in the middle of writing this Hangman game when out of know where I get this error.

1>------ Build started: Project: smj_cplusplus, Configuration: Debug Win32 ------
1>LINK : fatal error LNK1104: cannot open file 'c:\users\<username>\documents\visual studio 2015\Projects\smj_cplusplus\Debug\smj_cplusplus.exe'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

The issue of opening files seems to be an on going problem with this current compiler. Never the less here is the code just incase it is the reason for the error.

cplusplus Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <ctime>
  4. #include <string>
  5. #include <vector>
  6. #include <Windows.h>
  7. using std::cin;
  8. using std::cout;
  9. using std::string;
  10. using std::vector;
  11.  
  12. /*
  13. Written By: Smjprogrammer
  14. Microsoft Visual Studio Community 2015
  15. main.cpp
  16. */
  17.  
  18. #define t TEXT
  19. #define l lstrlen
  20. #define I INFINITE
  21.  
  22. class Game
  23. {
  24. private:
  25. HANDLE h = GetStdHandle (STD_OUTPUT_HANDLE), h2 = GetStdHandle (STD_INPUT_HANDLE);
  26. const int MAX_WRONG = 8;
  27. int wrong = 0;
  28. public:
  29. Game()
  30. {
  31. SetConsoleTitle (t ("Hangman"));
  32. SetConsoleTextAttribute (h, 0x0A);
  33. srand ((unsigned int)time(nullptr));
  34. }
  35.  
  36. void clear_screen()
  37. {
  38. DWORD n, size;
  39. COORD coord = {0};
  40. CONSOLE_SCREEN_BUFFER_INFO csbi;
  41. GetConsoleScreenBufferInfo (h, &csbi);
  42. size = csbi.dwSize.X * csbi.dwSize.Y;
  43. FillConsoleOutputCharacter (h, t(' '), size, coord, &n);
  44. GetConsoleScreenBufferInfo (h, &csbi);
  45. FillConsoleOutputAttribute (h, csbi.wAttributes, size, coord, &n);
  46. SetConsoleCursorPosition (h, coord);
  47. }
  48.  
  49. wchar_t Press_Any_Key_To_Continue()
  50. {
  51. wchar_t *b, c;
  52. unsigned long d, e;
  53. b = t ("Press any key to continue . . . ");
  54. WriteConsole (h, b, l (b), &e, 0);
  55. GetConsoleMode (h2, &d);
  56. SetConsoleMode (h2, 0);
  57. WaitForSingleObject (h2, I);
  58. ReadConsole (h2, &c, 1, &e, 0);
  59. putchar ('\n');
  60. SetConsoleMode (h2, d);
  61. return c;
  62. }
  63.  
  64. void Hangman()
  65. {
  66. vector <string> words;
  67.  
  68. words.push_back("ACTOR"); words.push_back("BASIN");
  69. words.push_back("CHORD"); words.push_back("DRESS");
  70. words.push_back("EVENT"); words.push_back("FARTS");
  71. words.push_back("GUESS"); words.push_back("HOUSE");
  72. words.push_back("IMAGE"); words.push_back("JUICE");
  73. words.push_back("LUCKY"); words.push_back("MACAW");
  74. words.push_back("NERVE"); words.push_back("OCEAN");
  75. words.push_back("POKER"); words.push_back("QUART");
  76. words.push_back("RUBAL"); words.push_back("SHAPE");
  77. words.push_back("TIGER"); words.push_back("UNION");
  78. words.push_back("VALVE"); words.push_back("WROTH");
  79. words.push_back("XERIC"); words.push_back("YIELD");
  80. words.push_back("ZIPPY");// Five letter words.
  81.  
  82. words.push_back("BAGPIPE");
  83. words.push_back("HANGMAN");
  84.  
  85. words.push_back("DIFFICULT");
  86.  
  87. random_shuffle(words.begin(), words.end());
  88.  
  89. const string THE_WORD = words[0];
  90. string soFar(THE_WORD.size(), '\026'), used = "";
  91.  
  92. while ((wrong < MAX_WRONG) && (soFar != THE_WORD))
  93. {
  94. cout << "You have " << (MAX_WRONG - wrong) << " incorrect guesses left.\n"
  95. << "You've used the following letters:\n" << used << '\n'
  96. << "So far, the word is:\n" << soFar << '\n';
  97.  
  98. char guess;
  99.  
  100. cout << "Guess a letter: ";
  101. cin >> guess;
  102.  
  103. guess = toupper(guess);
  104.  
  105. while (used.find(guess) != string::npos)
  106. {
  107. cout << "You've already quessed " << guess << '\n'
  108. << "Enter your guess: ";
  109. cin >> guess;
  110.  
  111. guess = toupper(guess);
  112. }
  113.  
  114. used += guess;
  115.  
  116. if (THE_WORD.find(guess) != string::npos)
  117. {
  118. cout << "That's right! " << guess << " is in the word.\n";
  119.  
  120. for (unsigned int i = 0; i < THE_WORD.length(); i++)
  121. if (THE_WORD[i] == guess)
  122. soFar[i] = guess;
  123. }
  124. else
  125. {
  126. cout << "Sorry, " << guess << " is not in the word.\n";
  127. wrong++;
  128. }
  129. Press_Any_Key_To_Continue();
  130. clear_screen();
  131. }
  132.  
  133. if (wrong == MAX_WRONG)
  134. {
  135. cout << "Game Over! You have been hanged!\a\n";
  136. }
  137. else
  138. {
  139. cout << "You Win!\n";
  140. }
  141. cout << "The word was " << THE_WORD << '\n';
  142. }
  143. };
  144.  
  145. int main()
  146. {
  147. Game play;
  148. play.Hangman();
  149. }// main.cpp
  150.  
  151. #undef t
  152. #undef l
  153. #undef I
__________________
HP Laptop / AMD A4 - 3305 APU with Radeon HD Graphics 1.90 Ghz
Windows 10 64-Bit
Visual Studio Community 2015
Recommended Books - C++ All-In-One For Dummies / Webster's Computer Dictionary
Smjprogrammer is offline   Reply With Quote
Old Jun 21st, 2016, 7:00 PM   #2
FlakkenTime
Software Developer
 
FlakkenTime's Avatar
 
Join Date: Apr 2010
Location: Bay Area, CA
Posts: 268
Rep Power: 7 FlakkenTime is on a distinguished road
Re: Need Help With Hangman

My C++ is shit and I'm unwilling to set this up and spend the time figuring it out sorry.
Make sure the path to your file is correct. Note that different OS's / compilers / languages will also handle pathing differently.
One may accept: ~/games/file.txt
While another requires: /home/userName/games/file.txt
FlakkenTime is offline   Reply With Quote
Old Jun 22nd, 2016, 9:09 AM   #3
Smjprogrammer
Learning Very Basic Stuff
 
Smjprogrammer's Avatar
 
Join Date: Jan 2010
Location: United States
Posts: 978
Rep Power: 8 Smjprogrammer is on a distinguished road
Re: Need Help With Hangman

I took everything out of main() and did the usual Hello, world! deal, and then it worked fine. Meaning it is something having to do with the code. Why it is telling me it is a file issue is irritating.
__________________
HP Laptop / AMD A4 - 3305 APU with Radeon HD Graphics 1.90 Ghz
Windows 10 64-Bit
Visual Studio Community 2015
Recommended Books - C++ All-In-One For Dummies / Webster's Computer Dictionary
Smjprogrammer is offline   Reply With Quote
Old Jun 23rd, 2016, 10:31 AM   #4
FlakkenTime
Software Developer
 
FlakkenTime's Avatar
 
Join Date: Apr 2010
Location: Bay Area, CA
Posts: 268
Rep Power: 7 FlakkenTime is on a distinguished road
Re: Need Help With Hangman

Comment out all the code except what handles the file. Verify you can get it to open and just print contents or a string informing you it was successful. I bet that will fail. Fix that first.

Most likely as I said either the path to the file is wrong.
FlakkenTime is offline   Reply With Quote
Old Jun 23rd, 2016, 5:43 PM   #5
Smjprogrammer
Learning Very Basic Stuff
 
Smjprogrammer's Avatar
 
Join Date: Jan 2010
Location: United States
Posts: 978
Rep Power: 8 Smjprogrammer is on a distinguished road
Re: Need Help With Hangman

I have commented out the two functions in main(), and in it's place I put this.

cplusplus Syntax (Toggle Plain Text)
  1. string a = "Hello, world!\n";
  2. cout << a;

It prints it just fine, so now what do I do?
__________________
HP Laptop / AMD A4 - 3305 APU with Radeon HD Graphics 1.90 Ghz
Windows 10 64-Bit
Visual Studio Community 2015
Recommended Books - C++ All-In-One For Dummies / Webster's Computer Dictionary
Smjprogrammer is offline   Reply With Quote
Old Jun 23rd, 2016, 10:57 PM   #6
FlakkenTime
Software Developer
 
FlakkenTime's Avatar
 
Join Date: Apr 2010
Location: Bay Area, CA
Posts: 268
Rep Power: 7 FlakkenTime is on a distinguished road
Re: Need Help With Hangman

What I mean is take it a step at a time. Try to print the file. Make sure the file is being opened and you can print it before you move to the next step
FlakkenTime is offline   Reply With Quote
Old Jun 23rd, 2016, 10:58 PM   #7
FlakkenTime
Software Developer
 
FlakkenTime's Avatar
 
Join Date: Apr 2010
Location: Bay Area, CA
Posts: 268
Rep Power: 7 FlakkenTime is on a distinguished road
Re: Need Help With Hangman

Sorry, I've spent last 4 years doing mostly python with dashes of ruby and a spice of php. Before that was 2 years of perl. If you switched to Python I'd be a lot more help :-P
FlakkenTime is offline   Reply With Quote
Old Jun 24th, 2016, 10:03 AM   #8
Smjprogrammer
Learning Very Basic Stuff
 
Smjprogrammer's Avatar
 
Join Date: Jan 2010
Location: United States
Posts: 978
Rep Power: 8 Smjprogrammer is on a distinguished road
Re: Need Help With Hangman

There are a few things I am going to try, but there is no file I am trying to open. If it is the header files you are talking about seems to me like it would underline it.
__________________
HP Laptop / AMD A4 - 3305 APU with Radeon HD Graphics 1.90 Ghz
Windows 10 64-Bit
Visual Studio Community 2015
Recommended Books - C++ All-In-One For Dummies / Webster's Computer Dictionary
Smjprogrammer is offline   Reply With Quote
Old Jun 24th, 2016, 10:18 AM   #9
Smjprogrammer
Learning Very Basic Stuff
 
Smjprogrammer's Avatar
 
Join Date: Jan 2010
Location: United States
Posts: 978
Rep Power: 8 Smjprogrammer is on a distinguished road
Re: Need Help With Hangman

Ok I just got the program to run. Instead of Debug I switched it to Release. Why it needed this is beyond me. All I know is it is good enough for now. Still not entirely happy as I get this along with it. I hope this means something to somebody.

1>  0 of 228 functions ( 0.0%) were compiled, the rest were copied from previous compilation.
1>    0 functions were new in current compilation
1>    0 functions had inline decision re-evaluated but remain unchanged
1>  smj_cplusplus.vcxproj -> C:\Users\Smjprogrammer\documents\visual studio 2015\Projects\smj_cplusplus\Release\smj_cplusplus.exe
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
__________________
HP Laptop / AMD A4 - 3305 APU with Radeon HD Graphics 1.90 Ghz
Windows 10 64-Bit
Visual Studio Community 2015
Recommended Books - C++ All-In-One For Dummies / Webster's Computer Dictionary
Smjprogrammer is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hangman Game flanneryaug Python 6 Jan 25th, 2011 12:11 PM
Another round of Hangman - Noobie looking for pointers! DaveNoobie Python 1 Oct 15th, 2009 12:41 AM
Hangman sbob60 Java 7 Oct 2nd, 2007 6:38 PM
[Ruby] Hangman Jessehk Show Off Your Open Source Projects 0 Mar 16th, 2006 9:55 PM
[Python] Simple Hangman game Jessehk Show Off Your Open Source Projects 5 Jan 24th, 2006 8:36 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:56 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC