943,936 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2400
  • C++ RSS
Jun 6th, 2005
0

Linker Error when program is run (Urgent help required Please")

Expand Post »
I have copied this program from this site, and simply copied as a new C++ file
but when run I got a number of error. so I included Myheader file which amongs other includes, the iostream.h, and stlib.h, that is why they have been commented out below. Any way doing this I have then run the program, and got a syntax error so I commented out line six as well, as shown below, but then still couldn't get the program to run, I keep getting this error

Linker error: undefined sysmbol_system in module game1.cpp
"game1 is what have named the program"


C++ Syntax (Toggle Plain Text)
  1. #include"myheader.h"
  2. #include<iostream.h>
  3. #include<time.h>
  4. #include<stdlib.h>
  5. #include<windows.h>
  6. //using namespace std;
  7. void one();
  8. void two();
  9. void three();
  10. void four();
  11. void five();
  12. void six();
  13. //Declare Functions used
  14. int main()
  15. {
  16. short unsigned int score = 0;
  17. short unsigned int compScore = 0;
  18. short unsigned int num = 0;
  19. short unsigned int num2 = 0;
  20. short unsigned int compNum = 0;
  21. short unsigned int compNum2 = 0;
  22. short unsigned int sum = 0;
  23. short unsigned int compSum = 0;
  24. char letter='j';
  25. //Declare Variables
  26. srand(time(NULL));
  27. //Initialize random number generator
  28. system("title Joe's Dice Game");
  29. while ( letter != 'q' )
  30. {
  31. cout << "Your Score: " << score << endl;
  32. cout << "computer's Score: " << compScore << endl << endl;
  33. cout << "Press r to roll or q to quit: ";
  34. cin >> letter;
  35. num = 1 + rand() % (6 - 1 + 1);
  36. num2 = 1 + rand() % (6 - 1 + 1);
  37. compNum = 1 + rand() % (6 - 1 + 1);
  38. compNum2 = 1 + rand() % (6 - 1 + 1);
  39.  
  40. //Random numbers
  41.  
  42. sum = num + num2;
  43. compSum = compNum + compNum2;
  44.  
  45. //Calculate Sums
  46.  
  47. if ( letter == 'q' )
  48. break;
  49. if ( letter != 'r' )
  50. {
  51. system("cls");
  52. continue;
  53. }
  54.  
  55. switch ( num )
  56. {
  57. case 1:
  58. one();
  59. break;
  60. case 2:
  61. two();
  62. break;
  63. case 3:
  64. three();
  65. break;
  66. case 4:
  67. four();
  68. break;
  69. case 5:
  70. five();
  71. break;
  72. case 6:
  73. six();
  74. break;
  75. default:
  76. cout << "Error...";
  77. break;
  78. } //end switch
  79.  
  80. switch ( num2 )
  81. {
  82. case 1:
  83. one();
  84. break;
  85. case 2:
  86. two();
  87. break;
  88. case 3:
  89. three();
  90. break;
  91. case 4:
  92. four();
  93. break;
  94. case 5:
  95. five();
  96. break;
  97. case 6:
  98. six();
  99. break;
  100. default:
  101. cout << "Error...";
  102. break;
  103. } //end switch
  104.  
  105. cout << endl << "Yours: " << num << ", " << num2 << endl;
  106. cout << "Computer's: " << compNum << ", " << compNum2 << "\n\n";
  107.  
  108. //Display dice and numbers
  109.  
  110. if ( sum > compSum )
  111. {
  112. cout << "You won!!" << endl << endl;
  113. score++;
  114. }
  115. else
  116. {
  117. compScore++;
  118. cout << "you lost..." << endl << endl;
  119. }
  120.  
  121. //Calculate score
  122.  
  123. system("pause");
  124. system("cls");
  125.  
  126. if ( score == 12 )
  127. {
  128. MessageBox(0, "You Won!!!", "Results:", MB_ICONEXCLAMATION);
  129. break;
  130. }
  131. if ( compScore == 12 )
  132. {
  133. MessageBox(0, "You lost...", "Results:", MB_ICONEXCLAMATION);
  134. break;
  135. }
  136. }
  137. return 0;
  138. }
  139.  
  140. void one()
  141. {
  142. cout << " -----" << endl;
  143. cout << "| |" << endl;
  144. cout << "| O |" << endl;
  145. cout << "| |" << endl;
  146. cout << " -----" << endl;
  147. }
  148. void two()
  149. {
  150. cout << " -----" << endl;
  151. cout << "| O|" << endl;
  152. cout << "| |" << endl;
  153. cout << "|O |" << endl;
  154. cout << " -----" << endl;
  155. }
  156. void three()
  157. {
  158. cout << " -----" << endl;
  159. cout << "| O|" << endl;
  160. cout << "| O |" << endl;
  161. cout << "|O |" << endl;
  162. cout << " -----" << endl;
  163. }
  164. void four()
  165. {
  166. cout << " -----" << endl;
  167. cout << "|O O|" << endl;
  168. cout << "| |" << endl;
  169. cout << "|O O|" << endl;
  170. cout << " -----" << endl;
  171. }
  172. void five()
  173. {
  174. cout << " -----" << endl;
  175. cout << "|O O|" << endl;
  176. cout << "| O |" << endl;
  177. cout << "|O O|" << endl;
  178. cout << " -----" << endl;
  179. }
  180. void six()
  181. {
  182. cout << " -----" << endl;
  183. cout << "|O O|" << endl;
  184. cout << "|O O|" << endl;
  185. cout << "|O O|" << endl;
  186. cout << " -----" << endl;
  187. }
<< moderator edit: added [code][/code] tags and indenting >>
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nike123 is offline Offline
20 posts
since Jun 2005
Jun 6th, 2005
0

Re: Linker Error when program is run (Urgent help required Please")

Is that the exact error or your rendition of the error?
Reputation Points: 35
Solved Threads: 3
Posting Whiz in Training
Dogtree is offline Offline
232 posts
since May 2005
Jun 7th, 2005
0

Re: Linker Error when program is run (Urgent help required Please")

I think you should comment out the first line.

//#include"myheader.h"
#include<iostream.h>
#include<time.h>
#include<stdlib.h>
#include<windows.h>
...
Reputation Points: 14
Solved Threads: 3
Light Poster
amt_muk is offline Offline
48 posts
since May 2005
Jun 7th, 2005
0

Re: Linker Error when program is run (Urgent help required Please")

yes that's exactly the error have got.

once i comment the first line, I get loads more errors.

Am guessing maybe that game is rather a C++ project, but i have tried creating it as a project but still no success. Uhh I don't know

can smeone please try and copy the game from http://www.daniweb.com/techtalkforums/thread5123.html
and see if you can get it to work.

Thank you
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nike123 is offline Offline
20 posts
since Jun 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: how to get a Local network domainNames and computernames using c++ in win32API
Next Thread in C++ Forum Timeline: C++ sequential files.





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


Follow us on Twitter


© 2011 DaniWeb® LLC