Write a functional decomposition and a C++ program that reads a time in numeric form and prints it in English

BustaBust

Golden Member
Dec 21, 2001
1,425
2
81
I fixed it, but it won't say AM or PM when you get to 10,15,20,25,30,35,40,45,50,55,60
Done on purpose to avoid further headaches.

Thanks everyone!
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Undefined symbol errors mean the linker can't find an actual address to correspond to a name you've used. If this isn't due to simply leaving a necessary .lib out of the build, then it is usually due to mismatched calling conventions. For example I see that the compiler is mangling the function name digit. If that name is really in a C library and not mangled, then you'd get this error. You can prevent name mangling by declaring it as extern "C".
 

BustaBust

Golden Member
Dec 21, 2001
1,425
2
81
This is what happened when I placed a "Extern C;" in the variables section

Error on line 9 (Extern C; )

Error 1 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\documents and settings\maulin\my documents\visual studio 2008\projects\time\time\time.cpp 15 Time


If I get rid of the 'int assumed' error, do I need to replace all digit with anything?


 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
The code, as posted, has the following problems:

1) Your function prototype is inside main(), which makes the compiler thing you're trying to call function digit, not define it. If you want to define function digit, put the prototype outside main (above main in the file), and call the function. Something like this:

// includes
// fcn prototype
void digits(int minutes);

using namespace std;
int main() { // etc ...

// second switch statement
digits(minutes);

// rest of main
} // curly brace to close main

// Now define digits down here
void digits(int minutes) {
// code for digits goes here
}


2) The extern C isn't required, and you should get rid of it. As an aside, you'd have to put it around the function prototype, but you don't need it anyway.

Edit: Added definition of digits above.
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
Originally posted by: Markbnj
Props to degibson for deciphering that code block :). I didn't even try.

I really wish they would fix the attach code "feature"... or at least remove the option to do it so it forces people to keep it in their OP... at least that way we only have to worry about the formatting engine mangling array indexes!
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
I'll bring it up in the mod area and see what they say, but we're a small corner of a really big site, as you guys all know, so don't hold your breath.
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
You're getting warmer BustaBust --
You need to close main with a } before starting another function, and you need to start a function with { not ;

Do the following:

On line 75, add a function call to digits. The exact syntax is: digits(minutes);
On line 76, close main. The exact syntax is: }
Line 79 is not supposed to be a prototype -- it is supposed to be a definition. Make it a definition by changing the ; to a {
(note that the closing } for this function is already there on 112, currently closing main.)

Edit: I'm lecturing about brace matching, and yet I somehow forget to close a parenthesis
 

BustaBust

Golden Member
Dec 21, 2001
1,425
2
81
Error 2 error C2065: 'hours' : undeclared identifier c:\documents and settings\maulin\my documents\visual studio 2008\projects\time\time\time.cpp 101 Time
Error 3 error C2065: 'hours' : undeclared identifier c:\documents and settings\maulin\my documents\visual studio 2008\projects\time\time\time.cpp 101 Time
Error 4 error C2065: 'hours' : undeclared identifier c:\documents and settings\maulin\my documents\visual studio 2008\projects\time\time\time.cpp 105 Time
Error 5 error C2065: 'hours' : undeclared identifier c:\documents and settings\maulin\my documents\visual studio 2008\projects\time\time\time.cpp 105 Time
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
When you are trying to use 'hours' in your code the compiler is complaining that it doesn't know what 'hours' is. Usually because you didn't declare that variable in the same scope that you are trying to use it.
 

BustaBust

Golden Member
Dec 21, 2001
1,425
2
81
I will admit that whole section where the error is, is all about minutes.
Hours were up there in a switch.

So what do I do? haha
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
So after looking at your code again, I have no idea what you want digits() to do. I didn't notice the calls to digit(), e.g. digits(minutes-20) on (original) line 84. But I have a new set of deltas for you, starting with the original file:

1) remove the (redundant) function prototype of digits from line 79
-- all code should now be in 'main', and you should be back to your original linker error (if not, make it so)

2) Add the following to the end of your file

void digits(int minutes) {
// Whatever you want digits to do, here
}