switch and random num generator

This is a discussion on switch and random num generator within the C++ Programming forums, part of the General Programming Boards category; But that's basically just another way of doing Code: num1 = rand() % 100;...

  1. #16
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,663
    But that's basically just another way of doing
    Code:
    num1 = rand() % 100;
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    without calling rand twice.

    so it would be like this:
    Code:
    srand(time(NULL)); // allows for random number generation
    num1 = rand();
    num1 %= 100;
    num2 = rand(); // picks a second random number that will not be the first
    num2 %= 100;

  3. #18
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,663
    Yes, perhaps that is what the teacher meant.
    Anyway, it can be done either way. You can pick one.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stack operations from switch statement elements
    By mlsrar in forum C Programming
    Replies: 15
    Last Post: 10-02-2008, 01:12 PM
  2. Random math problems
    By got1sleeve in forum C++ Programming
    Replies: 3
    Last Post: 01-23-2008, 10:20 PM
  3. Switch Statement
    By DarkDot in forum C++ Programming
    Replies: 11
    Last Post: 03-28-2007, 10:11 PM
  4. ascii rpg help
    By aaron11193 in forum C Programming
    Replies: 18
    Last Post: 10-29-2006, 01:45 AM
  5. A switch that doesn't switch
    By Death_Wraith in forum C++ Programming
    Replies: 5
    Last Post: 11-06-2004, 11:18 AM

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