473,405 Members | 2,185 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,405 software developers and data experts.

Problem with Function

sonic
40
I have a program for class that I must write using functions. Before I continued with the program I wanted to see if I could get my initial call to my first function working. Have not had luck though. Here are the error messages I'm recieving:

"error LNK2019: unresovled external symbol_main referenced in function_tmainCRTStartup"

"fatal error LNK1120: 1 unresolved externals"

Here's a copy of my code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. // Function prototypes
  6.  
  7. void printError();
  8. void getInput(int&, char&);
  9. void printLastLine(int, char);
  10. int printPattern(int, char);
  11.  
  12. int main()
  13. {
  14.     int numRows;
  15.     char typeChar;
  16.  
  17.     getInput();
  18. //    printPattern(inputNum, inputChar);
  19. //    printLastLine(inputNum, inputChar);
  20.  
  21.     return 0;
  22. }
  23.  
  24. //************************************************************************
  25. // Definition of getInput which obtains user info on how to build pattern*
  26. //************************************************************************
  27.  
  28. void getInput(int&, char&)
  29. {    
  30.     int inputNum = 0;
  31.     char inputChar = 0;
  32.  
  33.     cout << "How many rows do you want in the pattern (even numbers only: 2-14)?\n";
  34.     cin >> inputNum;
  35.     cout << "What character do you want the pattern made of (select: * + # or $)?\n";
  36.     cin >> inputChar;
  37.  
  38.     printError(inputNum&, inputChar&);
  39.  
  40.     return;
  41. }
  42.  
  43. //************************************************************************
  44. // Definition of printError which acts as input validation when program  *
  45. // is obtaining number and type of pattern to be used by user            *
  46. //************************************************************************
  47.  
  48. void printError ()
  49. {
  50.  
  51.     if ((inputNum < 2) || (inputNum > 14) ||(inputNum%2 != 0))
  52.         cout << "Invalid number of rows. Please retry.";
  53.         getinput();
  54.  
  55.         // Code here for 2nd validation (How to compare multiple literal strings?)
  56.  
  57.     return;
  58. }
  59.  
What am I doing wrong with the syntax? Thanks for any help!
Nov 27 '06 #1
9 1268
sicarie
4,677 Expert Mod 4TB
sonic-

I'm pretty sure it's that you define getInput() in the prototype to pass an int and a char, but when you call it in main, you don't pass it anything - you just instantiate them first thing in the function. Try passing those values.
Nov 27 '06 #2
teddarr
143 100+
OK, I got the getInput() function working and tested to make sure the inputs are passed to main(). Pay close attention to your function prototypes, function calls and function definitions.

One tip I was give is that once you have written your function and have the definition written, copy and paste in just like it is to the function prototype section. While all of this info is not required, it sure cuts down on confusion.

I didn't touch printerror() since you didn't mention any problems with it.

#include <iostream>
using namespace std;

// Function prototypes

void printError();
void getInput(int& inputNum, char& inputChar); //copy and paste from function definition, line 27
void printLastLine(int, char);
int printPattern(int, char);

int main()
{
int numRows;
char typeChar;

getInput(numRows, typeChar);
// printPattern(inputNum, inputChar);
// printLastLine(inputNum, inputChar);

return 0;
}

//************************************************** **********************
// Definition of getInput which obtains user info on how to build pattern*
//************************************************** **********************

void getInput(int& inputNum, char& inputChar)
{
//deleted these declarations as they are now passed from main()

cout << "How many rows do you want in the pattern (even numbers only: 2-14)?\n";
cin >> inputNum;
cout << "What character do you want the pattern made of (select: * + # or $)?\n";
cin >> inputChar;

//printError(inputNum, inputChar); //change on this line

// return;//no return statement needed on a void function
}
Nov 27 '06 #3
sonic
40
Initially what I need the program to do is just ask the user for the information. I do need the function to pass entered info to another function but I have nothing initially to pass until user answers questions in getInput function. Am I going about this wrong?
Nov 27 '06 #4
sonic
40
Sorry, meant to post code.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. // Fution prototypes
  5.  
  6. void printError();
  7. void getInput(int&, char&);
  8. void printLastLine(int, char);
  9. int printPattern(int, char);
  10.  
  11. int main()
  12. {
  13.     int inputNum = 0;
  14.     char inputChar = 0;
  15.  
  16.     getInput(inputNum, inputChar);
  17. //    printPattern(inputNum, inputChar);
  18. //    printLastLine(inputNum, inputChar);
  19.  
  20.     return 0;
  21. }
  22.  
  23. //************************************************************************
  24. // Definition of getInput which obtains user info on how to build pattern*
  25. //************************************************************************
  26.  
  27. void getInput(int&, char&)
  28. {    
  29.  
  30.     cout << "How many rows do you want in the pattern (even numbers only: 2-14)?\n";
  31.     cin >> inputNum;
  32.     cout << "What character do you want the pattern made of (select: * + # or $)?\n";
  33.     cin >> inputChar;
  34.  
  35.     printError(inputNum&, inputChar&);
  36.  
  37. }
  38.  
Nov 27 '06 #5
teddarr
143 100+
I think you need to look at the call for printerror. I've never seen a call like that. I don't think you use the '&' character in a call.
Nov 27 '06 #6
sivadhas2006
142 100+
I have a program for class that I must write using functions. Before I continued with the program I wanted to see if I could get my initial call to my first function working. Have not had luck though. Here are the error messages I'm recieving:

"error LNK2019: unresovled external symbol_main referenced in function_tmainCRTStartup"

"fatal error LNK1120: 1 unresolved externals"

Here's a copy of my code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. // Function prototypes
  6.  
  7. void printError();
  8. void getInput(int&, char&);
  9. void printLastLine(int, char);
  10. int printPattern(int, char);
  11.  
  12. int main()
  13. {
  14.     int numRows;
  15.     char typeChar;
  16.  
  17.     getInput();
  18. //    printPattern(inputNum, inputChar);
  19. //    printLastLine(inputNum, inputChar);
  20.  
  21.     return 0;
  22. }
  23.  
  24. //************************************************************************
  25. // Definition of getInput which obtains user info on how to build pattern*
  26. //************************************************************************
  27.  
  28. void getInput(int&, char&)
  29. {    
  30.     int inputNum = 0;
  31.     char inputChar = 0;
  32.  
  33.     cout << "How many rows do you want in the pattern (even numbers only: 2-14)?\n";
  34.     cin >> inputNum;
  35.     cout << "What character do you want the pattern made of (select: * + # or $)?\n";
  36.     cin >> inputChar;
  37.  
  38.     printError(inputNum&, inputChar&);
  39.  
  40.     return;
  41. }
  42.  
  43. //************************************************************************
  44. // Definition of printError which acts as input validation when program  *
  45. // is obtaining number and type of pattern to be used by user            *
  46. //************************************************************************
  47.  
  48. void printError ()
  49. {
  50.  
  51.     if ((inputNum < 2) || (inputNum > 14) ||(inputNum%2 != 0))
  52.         cout << "Invalid number of rows. Please retry.";
  53.         getinput();
  54.  
  55.         // Code here for 2nd validation (How to compare multiple literal strings?)
  56.  
  57.     return;
  58. }
  59.  
What am I doing wrong with the syntax? Thanks for any help!
Hi,

Can I know which IDE you are using to write the program?
Because this may be due to the IDE Settings.

Regards,
M.Sivadhas.
Nov 28 '06 #7
Hai Sonic,
As per your requirement, you are just using getInput() function to get some value. you are not doing anything with parameters, so i think you can just make this function with out any parameters like void getInput( void ); i feel this may do.

cheers,
kiruba.
Nov 28 '06 #8
sonic
40
I am using Microsoft Visual Studios 2005. I think my problem is that I really do not understand how functions work. Let me do some leg work and I'll get back when I have a little better understanding and have started over on my code. Thank you for help so far!
Nov 28 '06 #9
sonic
40
Okay, after two days of trying to figure out the inner workings of functions, I'm starting to gain some. Before I write the code for my printPattern function though I was hoping someone might be able to help me with a logic problem I'm having. It is in my printError function. I've got my input validation working for integers a user may enter, but for some reason I cannot get the function to correctly decide on whether or not the character entered is valid or not (* + # or $). Here is my code so far:

Expand|Select|Wrap|Line Numbers
  1. // PFunction(RDE).cpp
  2. // 11/26/06
  3. // Program allows user to select number and type of pattern to be printed to screen
  4.  
  5. #include <iostream>
  6. using namespace std;
  7.  
  8. // Function prototypes
  9.  
  10. void getInput(int&, char&);
  11. void printError(int&, char&);
  12. int printPattern(int, char);
  13.  
  14. int main()
  15. {
  16.     int numRows = 0;
  17.     char typeChar = 0;
  18.  
  19.     getInput(numRows, typeChar);
  20.  
  21.     return 0;
  22. }
  23.  
  24. //************************************************************************
  25. // Definition of getInput which obtains user info on how to build pattern*
  26. //************************************************************************
  27.  
  28. void getInput(int& rows, char& characterSelect)
  29. {
  30.  
  31.     cout << "How many rows do you want in the pattern (even numbers only: 2-14)? ";
  32.     cin >> rows;
  33.     cout << "What character do you want the pattern made of (select from: * + # or $)? ";
  34.     cin >> characterSelect;
  35.     printError(rows, characterSelect);
  36.  
  37. }
  38.  
  39. //************************************************************************
  40. // Definition of printError which determines if user has entered         *
  41. // acceptable input.                                                     *
  42. //************************************************************************
  43.  
  44. void printError(int& rows, char& characterSelect)
  45. {
  46.  
  47.     if ((rows < 2) || (rows > 14) || (rows%2 != 0))
  48.     {
  49.         cout << "\nInvalid number of rows. Please retry.\n";
  50.         cout << "\n";
  51.         getInput(rows, characterSelect);
  52.     }
  53.     else if ((characterSelect != '*') || (characterSelect != '+') || (characterSelect != '#') || (characterSelect != '$'))
  54.     {
  55.         cout << "\nInvalid character. Please retry using one of the four characters given.\n";
  56.         cout << "\n";
  57.         getInput(rows, characterSelect);
  58.     }
  59. }
  60.  
  61. //************************************************************************
  62. // Definition of printPattern displays pattern based on user entered data*
  63. //************************************************************************
  64.  
  65. int printPattern()
  66.  
Thanks for everyone's continued help and input.
Nov 29 '06 #10

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

Similar topics

1
by: Covad | last post by:
Hi all, For some reason my change() function is only called when the page loads. I'd much rather it gets called when the select changes. Here's the code: window.onload = init; function...
7
by: Emanuel Ziegler | last post by:
Hello, I want to do some mathematics with functions. In my case the function classes are very complex, but this simple example has the same problems. To allow calculations that begin with a...
117
by: Peter Olcott | last post by:
www.halting-problem.com
1
by: Mohamed Fysal | last post by:
I have written a Regular DLL with many Export Functions and one CALLBACK fun ction . The callback function declared in the .cpp file of the Regular DLL is as fol lows: typedef BOOL...
4
by: Andy_Khosravi | last post by:
Hello, I'm having a problem with the MID function within Access 97. I have been trying to build a function to check to make sure that a field on a form does not have any spaces or dashes. This...
0
by: Lucas, Todd | last post by:
Hello everyone! I'm having a problem with a WebControl that I'm designing for a Menu. I've been at it for about 3 weeks now, and can't seem to get around this problem. So I'm hoping that someone...
78
by: Josiah Manson | last post by:
I found that I was repeating the same couple of lines over and over in a function and decided to split those lines into a nested function after copying one too many minor changes all over. The only...
5
by: jbenner | last post by:
I have opened a PMR for this with IBM, and am not asking for advice from the DB2 DBA community. I am posting this as an FYI that DB2 Health Monitor, even at the latest version of DB2, still can cause...
2
by: Ravikiranreddy | last post by:
Hi every one, Am pasting the error code returned in log please help me in fixing it--- ERROR:An error occurred during the execution of the command "/opt/IBM/db2/V8.1/instance/dascrt -u...
6
by: pauldepstein | last post by:
Let double NR( double x, double(*)(const double&) f ) be the signature of a Newton-Raphson function NR. Here, f is a function which returns a double and accepts a const double&. The aim of...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.