Thread: A little Rusty (Need help with random)

  1. #1
    Twig
    Guest

    A little Rusty (Need help with random)

    Hey All,

    I haven't touched C in about 6 months. So considering I was never that good to begin with i'm having troubles. :-P Now i'm trying to do something for fun to get back into the swing of things. I'm making 2 arrays with nouns and insults. Each array has 10 nouns and 10 insults. I then want to generate two random numbers between 1 and 10 and then have it print off the number generate from the noun array and the insult array. Follow? Well I did it once. But for the life of me, I can't remember how I did it. This is what I have right now. It's not much to work with, but i was hoping you all could help refresh my memory.


    #include <stdio.h>

    char insult[7]{
    "******";
    "*";
    "**";
    "*";
    "*****";
    "***";
    "****";
    },

    I'm not even sure if the array is setup right. And yes theres only 7 insults for now. But I can change that to 10 on my own without problem. Any help would be very appretiated.

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    char insult[7]{
    "******";
    "*";
    "**";
    "*";
    "*****";
    "***";
    "****";
    },

    This is incorrect, you've created a 1-d array, and tried to assign 2-d information to it.

    As the array contents are going to be static, try this convention

    Code:
    char *insult[]{ 
    "******",
    "*",
    "**",
    "*",
    "*****",
    "***",
    "****"
    }
    As for random numbers, theres been like a whole bunch of posts on this over the past week or so, just browse this forum to find them.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. random to int?
    By psyadam in forum C# Programming
    Replies: 7
    Last Post: 07-22-2008, 08:09 PM
  2. Lesson #3 - Math
    By oval in forum C# Programming
    Replies: 2
    Last Post: 04-27-2006, 08:16 AM
  3. Another brain block... Random Numbers
    By DanFraser in forum C# Programming
    Replies: 2
    Last Post: 01-23-2005, 05:51 PM
  4. How do I restart a random number sequence.
    By jeffski in forum C Programming
    Replies: 6
    Last Post: 05-29-2003, 02:40 PM
  5. Best way to generate a random double?
    By The V. in forum C Programming
    Replies: 3
    Last Post: 10-16-2001, 04:11 PM