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: - #include <stdio.h>
-
#include <time.h>
-
-
void main ()
-
-
{
-
{
-
//Declare variables.
-
int GameChoice, Guess, Answer, Score(Guess, Answer);
-
-
//Ask user to chose a game.
-
printf("Please chose a game by entering its' number:\nPlay Dice => Enter 1 \nGuess a Number => Enter 2\n");
-
scanf("%d", &GameChoice);
-
-
//If the User chooses to Play Dice
-
{
-
int DieTotal, UserGuess;
-
if (GameChoice == 1)
-
{
-
//Let the computer select a number from 2 to 12.
-
srand(time(0));
-
DieTotal = 2 + rand() % 11;
-
-
//Ask user to select a number between 2 and 12.
-
printf("Select a number between 2 and 12: ");
-
scanf("%d", &UserGuess);
-
-
Score(Guess, Answer);
-
}
-
}
-
}
-
-
int Guess, Answer;
-
int Score(Guess, Answer)
-
{
-
if (Guess == Answer)
-
{
-
printf("\nYou won. The sum of the two numbers was %d.\n", Answer);
-
}
-
-
else (Guess != Answer);
-
{
-
printf("\nYou lost. The sum of the two numbers was actually %d.\n", Answer);
-
}
-
}
-
}
2 2048
This code: - //Declare variables.
-
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: - //Declare variables.
-
int GameChoice;
-
int Guess;
-
int Answer;
-
int Score(Guess, Answer);
-
-
Score would have been seen as a function prototype.
-
Try to avoid doing multiple things in your lines of code. It does nothing but make the code harder to read.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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.
|
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...
|
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...
|
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*)':...
|
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...
|
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...
|
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;
|
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...
|
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?.
...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
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)...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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
|
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...
| |