Using conio.h in C++

This is a discussion on Using conio.h in C++ within the C++ Programming forums, part of the General Programming Boards category; Hello, Everyone: My friend and I were doing a C++ program which relates to dice. Here is the problem: Write ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    30

    Using conio.h in C++

    Hello, Everyone:

    My friend and I were doing a C++ program which relates to dice. Here is the problem:

    Write a program that simulates the rolling of two dice. The program should use rand to roll the first die and should use rand again to roll the second die. The sum of the two values should then be calculated. [Note: Each die can show an integer value from 1 to 6, so the sum of the two values will vary from 2 to 12, with 7 being the most frequent sum and 2 and 12 being the least frequent sums.] Figure 7.32 shows the 36 possible combinations of the two dice. Your program should roll the two dice 36,000 times. Use a one-dimensional array to tally the numbers of times each possible sum appears. Print the results in a tabular format. Also, determine if the totals are reasonable.

    Here is the code:
    Code:
    // Include files
    #include <iostream>  // used for cin, cout
    #include <conio.h>
    #include <iomanip>
    #include <cstdlib>
    #include <ctime>
    using namespace std;
    
    // Global Type Declarations
    
    // Function Prototypes
    void instruct (void);
    void pause ();
    
    //Global Variables - should not be used without good reason.
    
    int main ()
    {
    	 // Declaration section
    
    	 const int arraySize = 13;           
             int die1,
    	     die2,
    	     frequency[ arraySize ] = { 0 };
    	 
    	 // Executable section
    	 instruct ();
    
    	 srand( time( 0 ) );
          
    	 //Roll Dice 36000 times store result in frequency array
    	 for ( int roll = 0; roll < 36000; ++roll ) {
                 die1 = 1 + rand() % 6;
                 die2 = 1 + rand() % 6;
                 ++frequency[ die1 + die2 ];
       }
         //Column Headers
         cout << setw( 10 ) << "Dice Combination" 
    		  << setw( 17 ) << "Frequency\n\n";
    
         //Start at Element 2 To Skip Elements 0 and Element 1
         for ( int combo = 2; combo < arraySize; ++combo )
         cout << setw( 9 ) << combo << setw( 18 ) << frequency[ combo ] 
    	  << endl; 
               
             pause ();
    	 return 0;
    }
    
    void instruct (void)
    {
    	  // Declaration section
         cout << "This program will simulate the rolling of two dice 36000 times. "
    		   << "It will then\nprint out the results of how many times each "
    		   << "combination of the two dice\nappeared. You should see in the "
    		   << "results that the 7 combination will appear\nthe most with the 2 "
    		   << "combination and the 12 combination appearing the least.\n"
    		   << "_______________________________________________________________"
    		   << "_____________"
    		   << "\n" << endl;
    
    	  // Executable section
    }
    
    void pause ()
    {
        // Declaration section
    
        // Executable section
        cout << "\nPress any key to continue...";
        getch();
        cout << "\r";
        cout << "                            ";
        cout << "\r";
    }
    However, the g++ compiler says that <conio.h> does not exist:
    Code:
    dice.cpp:3: conio.h: No such file or directory
    I understand <conio.h> is used in C not in C++, however, I need help finding out what <conio.h> means in C++. Please someone help us figure out the problem and what does conio.h means in C++. I will appreciate any help. Thank you.
    Last edited by mikeprogram; 12-01-2005 at 11:11 PM.

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    Why don't you take another look at that code you posted and try and see any relevance to the paragraph you wrote above it.

    Check to see if you have conio.h in your include folder of your compiler.
    Last edited by SlyMaelstrom; 12-01-2005 at 10:59 PM.
    Sent from my iPadŽ

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    30
    My apologies. I wrote accidentally the wrong program. The actual program is in the same post. Sorry about that!

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    I understand <conio.h> is used in C not in C++, however, I need help finding out what <conio.h> means in C++.
    http://www.bloodshed.net/dev/faq.html

  5. #5
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    I understand <conio.h> is used in C not in C++
    Says who??? conio.h is a non-standard file in either C or C++, what works with one compiler may or may not work with another compiler even if the two compilers are for the same operating system. The functions in that file were originally written by Borland for use by their compilers (Turbo C). Some (but not all) other compilers are also supporting some of the functions.

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,663
    Since it's perfectly possible to do the program without conio.h, why worry about it's non existence.

    You're only waiting for a key at the end, and that's discussed in the FAQ.

  7. #7
    Registered User
    Join Date
    Oct 2005
    Posts
    30
    Okay, thank you for your good advices to all of you who help me figure out what was the problem. I drop off <conio.h> and rearrange the code a little bit. Thank you once again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. conio.h not working in *nix
    By wise_ron in forum C Programming
    Replies: 2
    Last Post: 05-04-2006, 01:54 PM
  2. conio.h in Visual C++ ?
    By Born_2B_Alone in forum Windows Programming
    Replies: 3
    Last Post: 09-22-2004, 07:32 PM
  3. Getting textcolor in conio.h to work with Win32
    By MMD_Lynx in forum C Programming
    Replies: 5
    Last Post: 09-02-2004, 01:32 PM
  4. conio.h
    By Jaguar in forum Linux Programming
    Replies: 10
    Last Post: 10-17-2002, 01:12 AM
  5. Conio.h file problems
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 05-23-2002, 01:44 PM

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