Like Tree3Likes
  • 3 Post By Salem

create a program that ...

This is a discussion on create a program that ... within the C Programming forums, part of the General Programming Boards category; Create a program that will shuffle and display this statements. Yes it is. No it's not. I guess so. Okay ...

  1. #1
    Registered User
    Join Date
    Aug 2014
    Posts
    47

    create a program that ...

    Create a program that will shuffle and display this statements.
    Yes it is.
    No it's not.
    I guess so.
    Okay that's all.


    What do you think will be the code for this? Im a newbie. Please help

  2. #2
    zub
    zub is offline
    Registered User zub's Avatar
    Join Date
    May 2014
    Location
    Russia
    Posts
    104
    Code:
    #include <stdlib.h>     // rand, srand
    #include <time.h>       // time
    #include <stdio.h>      // puts
    
    
    const unsigned int shuffles[24][4] = {
        { 0, 1, 2, 3 },
        { 0, 1, 3, 2 },
        { 0, 2, 1, 3 },
        { 0, 2, 3, 1 },
        { 0, 3, 1, 2 },
        { 0, 3, 2, 1 },
        { 1, 0, 2, 3 },
        { 1, 0, 3, 2 },
        { 1, 2, 0, 3 },
        { 1, 2, 3, 0 },
        { 1, 3, 0, 2 },
        { 1, 3, 2, 0 },
        { 2, 0, 1, 3 },
        { 2, 0, 3, 1 },
        { 2, 1, 0, 3 },
        { 2, 1, 3, 0 },
        { 2, 3, 0, 1 },
        { 2, 3, 1, 0 },
        { 3, 0, 1, 2 },
        { 3, 0, 2, 1 },
        { 3, 1, 0, 2 },
        { 3, 1, 2, 0 },
        { 3, 2, 0, 1 },
        { 3, 2, 1, 0 }
    };
    
    
    int main(void)
    {
        const char* const phrases[4] = {
            "Yes it is.",
            "No it's not.",
            "I guess so.",
            "Okay that's all."
        };
    
    
        srand(time(NULL));
        const unsigned int* const shuffle = shuffles[rand() % 24];
    
    
        unsigned int i;
        for( i = 0; i < 4; ++i ) {
            puts(phrases[shuffle[i]]);
        }
    
    
        return 0;
    }
    Our goals are clear, tasks are defined! Let's work, comrades! -- Nikita Khrushchev

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    zub, please stop dumping complete answers with no further explanation, or without the OP making a significant contribution of their own.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    zub
    zub is offline
    Registered User zub's Avatar
    Join Date
    May 2014
    Location
    Russia
    Posts
    104
    In fact, it is a bit of a joke. If you look closely at the program, you will see that this is a very specific solution. I'm sure, topicstarter needs a more general solution. I'm just tired of the his monotonous questions. Let him disassemble my code. Perhaps he will understand how to formulate the following questions. His problem is not that he does not know the answer. He does not even know what question to ask. I just clarifying it.

    Sheckley Robert - Ask a Foolish Question
    Our goals are clear, tasks are defined! Let's work, comrades! -- Nikita Khrushchev

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Create a GUI for this program?
    By sellers04 in forum C Programming
    Replies: 4
    Last Post: 07-18-2011, 07:52 PM
  2. Program to create shapes in PPM
    By cpsestudent in forum C Programming
    Replies: 3
    Last Post: 02-08-2011, 02:11 AM
  3. Trying to create an exp(x) program
    By toadkiwi in forum C Programming
    Replies: 12
    Last Post: 02-29-2008, 05:29 AM
  4. Help me with my basic program, nothing I create will run
    By Ravens'sWrath in forum C Programming
    Replies: 31
    Last Post: 05-13-2007, 03:35 AM
  5. Create a file from c++ program
    By Dan17 in forum C++ Programming
    Replies: 2
    Last Post: 05-08-2006, 05:25 PM

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