473,326 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Undefined reference to 'Score'

Hi, I'm making a program to let a user guess the correct sum of two die, but I keep getting an error that says "Undefined reference to 'Score'." Can someone tell me how to fix it? My code looks like this:

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <time.h>
  3.  
  4. void main ()
  5.  
  6. {
  7.     {
  8.     //Declare variables.
  9.     int GameChoice, Guess, Answer, Score(Guess, Answer);
  10.  
  11.     //Ask user to chose a game.
  12.     printf("Please chose a game by entering its' number:\nPlay Dice => Enter 1 \nGuess a Number => Enter 2\n");
  13.     scanf("%d", &GameChoice);
  14.  
  15.     //If the User chooses to Play Dice
  16.     {
  17.     int DieTotal, UserGuess;
  18.     if (GameChoice == 1)
  19.         {
  20.             //Let the computer select a number from 2 to 12.
  21.             srand(time(0));
  22.             DieTotal = 2 + rand() % 11;
  23.  
  24.             //Ask user to select a number between 2 and 12.
  25.             printf("Select a number between 2 and 12: ");
  26.             scanf("%d", &UserGuess);
  27.  
  28.             Score(Guess, Answer);
  29.         }
  30.     }
  31.     }
  32.  
  33. int Guess, Answer;
  34. int Score(Guess, Answer)
  35.          {
  36.          if (Guess == Answer)
  37.             {
  38.                 printf("\nYou won. The sum of the two numbers was %d.\n", Answer);
  39.             }
  40.  
  41.         else (Guess != Answer);
  42.             {
  43.                 printf("\nYou lost. The sum of the two numbers was actually %d.\n", Answer);
  44.             }
  45.          }
  46. }
Oct 8 '11 #1
2 2048
weaknessforcats
9,208 Expert Mod 8TB
This code:

Expand|Select|Wrap|Line Numbers
  1. //Declare variables.
  2.  int GameChoice, Guess, Answer, Score(Guess, Answer);
isn't doing what you think it does. What is is doing is creating int variables. None of them are inititlaized except the last, which is a temp variable initiaized by a call to Score(Guess, Answer). Unfortunately, the compiler has not been made aware of Score as a function, so the compile fails.

Had you coded this way:
Expand|Select|Wrap|Line Numbers
  1. //Declare variables.
  2.  int GameChoice;
  3. int Guess;
  4. int Answer;
  5. int Score(Guess, Answer);
  6.  
  7. Score would have been seen as a function prototype.
  8.  
Try to avoid doing multiple things in your lines of code. It does nothing but make the code harder to read.
Oct 9 '11 #2
donbock
2,426 Expert 2GB
You have defined function Score within the body of function main. That is not allowed. Move the brace on line 46 (that terminates the body of function main) to line 32.

Line 33 is problematical. Delete that line and instead embed the types of the arguments in line 34.
Oct 12 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: RU | last post by:
Hi, I am working on a porting project to port C/C++ application from unixware C++, AT&T Standard components to g++ with STL on Linux. This application has been working properly on...
1
by: Codemutant | last post by:
**** Post for FREE via your newsreader at post.usenet.com **** I just cannot find what is undefined in this code.
1
by: Dom | last post by:
I'm new to c++. Just started learning it 24 hours ago. Am running into a compile problem. Please, no one waste the effort telling me to google it. I've been researching it for quite a while with no...
1
by: Andre Janssen | last post by:
Hi.... I tried to compile the following src with this command: "g++ -Wall -o bla alsaswitch.cpp". The src is an example src of xosd package. #include <xosd.h> int main (int argc, char...
3
by: Michael Sgier | last post by:
Hi i get thousands of messages like below. How shall i resolve that? Thanks Mcihael Release/src/Utility/RawImage.o: In function `CMaskImage::CMaskImage(int, int, char const*)':...
5
by: druberego | last post by:
I read google and tried to find the solution myself. YES I do know that you can get undefined references if you: a) forget to implement the code for a prototype/header file item, or b) you forget...
3
by: prakash.mirji | last post by:
Hello, I am getting below mention linker error when I tried to link my class test.C I use below command to compile test.C /usr/bin/g++ -g -fpic -fvisibility=default -D_POSIX_SOURCE...
1
by: taiyang902 | last post by:
i program under linux ,and using kdevelop c/c++. the code follow, #ifdef HAVE_CONFIG_H #include <config.h> #endif #include <iostream> #include <cstdlib> using namespace std;
2
by: zqiang320 | last post by:
Hello: I execute make ,then get error: $ make Making all in libsbml/src make: Entering directory `/home/internet/mydoc/test_pj/libsbml/src' ........ /bin/sh ./libtool --tag=CC --mode=link...
3
by: tvnaidu | last post by:
I compiled tinyxml files (.cpp files) and when I am linking to create final exe in Linux, I am getting lot of errors saying "undefiend reference" to "operator new" and "delete", any idea?. ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.