Posted: 10/10/2009 2:28:53 PM EDT
|
This is almost working I just need help with the getData definition
should be easy but i keep getting errors
|
|
they start right where i have /////////////////////getdata
1>p:\comp220\test\test\imp.cpp(98) : error C2144: syntax error : 'int' should be preceded by ';' 1>p:\comp220\test\test\imp.cpp(98) : error C2365: 'getData' : redefinition; previous definition was 'function' 1> p:\comp220\test\test\imp.cpp(16) : see declaration of 'getData' 1>p:\comp220\test\test\imp.cpp(99) : error C2059: syntax error : 'while' 1>p:\comp220\test\test\imp.cpp(100) : error C2447: '{' : missing function header (old-style formal list?)
|
|
Quoted:
they start right where i have /////////////////////getdata
1>p:\comp220\test\test\imp.cpp(98) : error C2144: syntax error : 'int' should be preceded by ';' 1>p:\comp220\test\test\imp.cpp(98) : error C2365: 'getData' : redefinition; previous definition was 'function' 1> p:\comp220\test\test\imp.cpp(16) : see declaration of 'getData' 1>p:\comp220\test\test\imp.cpp(99) : error C2059: syntax error : 'while' 1>p:\comp220\test\test\imp.cpp(100) : error C2447: '{' : missing function header (old-style formal list?) int getDataint choice = -1;while(choice < 0 || choice > sizeof(theMenu)/sizeof(menuItemType));{ showMenu(); // run the void showMenu() function cout << "\n" << choice << endl; choice = getData(number); // Returns the number the person chose the the array number }
The part after /////////////////////getdata kind of needs to be in a function or something. |
right duh
now just error C2065: 'number' : undeclared identifier . |
|
Not to mention that number is not defined in that scope. choice is apparently a function parameter and should probably not be declared like that nor initialized to -1.
ETA: And your prototype says that getData should take an int parameter and will return an int, not void. |
: error C4716: 'getData' : must return a value god i suck at this |
|
Quoted: they start right where i have /////////////////////getdata 1>p:\comp220\test\test\imp.cpp(98) : error C2144: syntax error : 'int' should be preceded by ';' 1>p:\comp220\test\test\imp.cpp(98) : error C2365: 'getData' : redefinition; previous definition was 'function' 1> p:\comp220\test\test\imp.cpp(16) : see declaration of 'getData' 1>p:\comp220\test\test\imp.cpp(99) : error C2059: syntax error : 'while' 1>p:\comp220\test\test\imp.cpp(100) : error C2447: '{' : missing function header (old-style formal list?) int getDataint choice = -1;while(choice < 0 || choice > sizeof(theMenu)/sizeof(menuItemType));{ showMenu(); // run the void showMenu() function cout << "\n" << choice << endl; choice = getData(number); // Returns the number the person chose the the array number }Uhh... Your 'int getData' defines an integer variable named getData.... You should have an: int getdata (int choice) { // Function code goes here } But what you have, is: int getData int choice { } |
should be the last piece of the puzzle? |
|
Well, your while loop is also incorrectly defined. A semi-colon at the end is interpreted as a null statement. The code between the curly braces isn't part of the loop.
You're also recursively calling getData. I hope you know what you're doing, otherwise you're bound to encounter a case of infinite recursion and probably a stack overflow. |
|
Quoted: int getData(){int choice = 0;while(choice < 0 || choice > sizeof(theMenu)/sizeof(menuItemType));{ showMenu(); // run the void showMenu() function cout << "\n" << choice << endl; choice = getData(choice); // Returns the number the person chose the the array number}}: error C4716: 'getData' : must return a value god i suck at this yes... Not only did you create a 'GetData' function without a 'getData =' at the end.... But you will have some real 'fun' if you try to run the above code-snippet once you add one... 2 words: Infinite Loop |
|
Quoted:
Well, your while loop is also incorrectly defined. A semi-colon at the end is interpreted as a null statement. The code between the curly braces isn't part of the loop. You're also recursively calling getData. I hope you know what you're doing, otherwise you're bound to encounter a case of infinite recursion and probably a stack overflow. typo
and no....sadly i dont |
|
Quoted:
Quoted:
Well, your while loop is also incorrectly defined. A semi-colon at the end is interpreted as a null statement. The code between the curly braces isn't part of the loop. You're also recursively calling getData. I hope you know what you're doing, otherwise you're bound to encounter a case of infinite recursion and probably a stack overflow. typo
and no....sadly i dont Well, enjoy a crash course in debugging code that compiles but doesn't run.
|
Win a FREE Membership!
Sign up for the ARFCOM weekly newsletter and be entered to win a free ARFCOM membership. One new winner* is announced every week!
You will receive an email every Friday morning featuring the latest chatter from the hottest topics, breaking news surrounding legislation, as well as exclusive deals only available to ARFCOM email subscribers.
.numOrdered to all 0's.