![]() |
|
#1
|
|||
|
|||
Small Help NeededModify the following code to print - Welcome to My World of Computing -without changing the body of main().
CPP / C++ / C Code:
Last edited by dsmith : 01-Nov-2004 at 13:30.
Reason: Please use [c] & [/c] for syntax highlighting
|
|
#2
|
||||
|
||||
|
Quote:
My answer is no. That is because my compiler (gnu c++) will not compile a C++ program that does not have a return value of int. However, if you were to ask the same question of: CPP / C++ / C Code:
My answer would be yes. You need to do it with operator overloading. Look here for information on the basics of how this is done. Be warned, this is not as straight forward as it may seem. I did get it to work, but the string literal was a tough thing for me to overcome. I am not a C++ expert, so I am calling out those of you that are C++ experts to see what you get. I will post my ugly answer after I see a few replies... __________________
The best damn Sports Blog period. Last edited by dsmith : 01-Nov-2004 at 15:43.
|
|
#3
|
||||
|
||||
|
You need to pay attention to the simple stuff. If you use something like cout your compiler needs to know, therefor the include.
CPP / C++ / C Code:
You could also do it this way. CPP / C++ / C Code:
or even this, CPP / C++ / C Code:
Listen to dsmith, use the code tags and pay attention. This is the most basic type of program. If you don't read your compiler's errors you can't fix them for yourself. Make sure to run in a shell that does not close so you can get all the info you need. It is there to help. __________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work." --Thomas Alva Edison "Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety." --Benjamin Franklin "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes." --Hugh Downs |
|
#4
|
||||
|
||||
|
hehe cable_guy_67. That is all good advice, but you should read his directions again
:Quote:
Right now the program only prints "My World of Computing", but you need to make it print "Welcome to My World of Computing" without changing the main function! I am not a very good C++ programmer. (I dare say this can not be done in C at all though - I'm calling you out, Walt!). It took me a while to figure it out. If you get a chance, you should try it. It was p***ing me off pretty severely! This can be done with operator overloading and at first looks pretty straight forward. Give it a try! Hint: the problem has a lot to do with the string literal. __________________
The best damn Sports Blog period. |
|
#5
|
||||
|
||||
|
Quote:
WHAT A MONKEY I AM!!! I am not worthy, I am not worthy, I spent all afternoon on a different problem. Sorry 'bout that. I should learn how to follow directions. I will have to think about this. Walt! Save us from ourselves, or at the very least me from me. I must apologize for my haste, I'm usually not this cranky. __________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work." --Thomas Alva Edison "Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety." --Benjamin Franklin "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes." --Hugh Downs |
|
#6
|
||||
|
||||
|
Quote:
Well, I proved myself wrong! It is actually simpler in C (IMO). Here is the C challenge. Take this & without changing the main function, make it print "Welcome to My World of Computing" CPP / C++ / C Code:
I am actually kind of embarrased about saying that it couldn't be done in C! __________________
The best damn Sports Blog period. |
|
#7
|
||||
|
||||
|
Quote:
CPP / C++ / C Code:
But CPP / C++ / C Code:
Maybe you can PM your answers to me or D (don't yet, please) and we can compile a list of solutions... Whatcha think, D? __________________
Cow: You're a lawyer too? Mooseblood (mosquito): Ma'am, I was already a bloodsucking parasite. All I needed was a briefcase! |
|
#8
|
||||
|
||||
|
Quote:
Good idea. If everyone wants to PM me their answers, we will see who comes up with the best solutions and you will get a prize beyond your wildest dreams: Our respect and admiration! (nah....) Remember, there are two riddles, the original C++ one and the C one. I've got my answers! __________________
The best damn Sports Blog period. |
|
#9
|
||||
|
||||
|
Quote:
You should be carefull about your statements. Some people don't use the same compiler as you do (I am guessing .NET?); in VC++ 6, for example, cout has nothing to do with std. As for your little "competition", I onestly found the "problem" easy to solve; I don't mean to be haughty or anything....If you really want too, i could send you my solution; actually, I am really curious about the C version; I mean I'm not sure if someone didn't find a nicer solution than mine; maybe we could just post it here, since this is still a forum Best regards, Luci __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
|
#10
|
||||
|
||||
|
Quote:
Just PM for now. I think others may want to do this and I don't want to give the answers out. I am glad that you got it easily, because it drove me nuts for about 20 minutes! The C was really easy though once I thought about it. I've already got answers from Dave, which are completely different than mine but valid. It will be interesting to see how many ways this cat can be skinned. So I say for now, don't post your answers here. I will post all of the solutions after a bit. __________________
The best damn Sports Blog period. |
Recent GIDBlog
Prepping for deployment by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| help with coding expectation maximization needed. thanks | edge | C Programming Language | 8 | 08-Nov-2005 05:00 |
| Some small things | Allowee | GIDSearch™ | 6 | 14-Jul-2004 01:40 |
| This is a small snippet from a much larger piece. | Tang_Quester | Open Discussion Forum | 1 | 19-Mar-2004 01:17 |
| Free 1st month / Free setup / No credit card needed...Plans start at 4.95 | LarryIsaac | Web Hosting Advertisements & Offers | 0 | 11-Oct-2003 14:03 |
| Script needed for letting user input a few days of data for tracking and analysis. | tradertt | MySQL / PHP Forum | 3 | 06-Mar-2003 02:54 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The