Need help with a small program

This is a discussion on Need help with a small program within the C++ Programming forums, part of the General Programming Boards category; ........

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    1

    Need help with a small program

    .....
    Last edited by supradriver; 04-27-2009 at 04:49 PM.

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,802
    #1. main should return an int.

    #2.
    Code:
    char getrand;
    I somehow doubt a getrand function returns a char, and if it does that is not the way to declare a function - or is it something else. Where is the code for the function, what is it supposed to do?

    #3.
    Your noun/verb/article/preposition functions do nothing other than allocate space for a local array which is immediately thrown away once the functions end. At the very least you'd need to be passing something into or out of the functions or returning something or setting a global variable within the functions to get anything happening after a call. It seems - in theory - that you'd either want to pass the index returned from the getrand function call into the function and return a char pointer to one a word in the array, or you'd call getrand locally in each noun/verb/preposition/article function and again use that to return a char pointer to one of the words. In either case, if you insist on using functions for these, this should be done with the arrays declared as static. I'd probably simply go with all these array declared locally in main for such a simple program and forego the use of functions for that purpose.

    I'm guessing you need to call the "getrand" function once for each noun/article/verb/preposition that you wish the final sentence to contain. The argument to getrand, if any, is probably a range of values 0-N where N is one minus the number of array values you are trying to index into (which could theoretically be different for each class of noun/verb, etc...). You then need to set individual char pointers (not simple chars) according to the indexed words and then print out sentence using the char pointers (%s, not %c).

    [edit]And since this is the C++ board, you should probably consider std::strings and C++ I/O streams instead of char arrays and printf... unless you're constrained in that manner.[/edit]
    Last edited by hk_mp5kpdw; 04-27-2009 at 04:16 PM.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Please Help with small program
    By cjohnman in forum C Programming
    Replies: 11
    Last Post: 04-14-2008, 09:59 AM
  2. Program to reverse a number. small error with it..
    By comproghelp in forum C Programming
    Replies: 8
    Last Post: 11-22-2004, 09:52 AM
  3. Help writing small program
    By guitarhead2000 in forum C++ Programming
    Replies: 2
    Last Post: 10-13-2004, 12:42 PM
  4. A little Help with a small program
    By whtpirate in forum C Programming
    Replies: 7
    Last Post: 06-05-2003, 06:15 PM
  5. Very small program...Whats wrong???
    By SmokingMonkey in forum C++ Programming
    Replies: 4
    Last Post: 05-30-2003, 09:09 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21