Strange bug....

This is a discussion on Strange bug.... within the C++ Programming forums, part of the General Programming Boards category; Hi When i compile my code, it works alright, no errors, but when i run it, i get to a ...

  1. #1
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321

    Strange bug....

    Hi
    When i compile my code, it works alright, no errors, but when i run it, i get to a certain point where the program sort of goes out of control.
    Here is the code:

    Code:
    #include <iostream>     
    using namespace std;        
    
    int main()      
    {
       int DOB;
       int AGE;
       int MONTH;
       int DATE;
       do      
       {
    	   cout << "Please enter your date of birth...\n" << endl;
    	   cin >> DOB;        
    	   cin.ignore();        
    	   if (DOB < 2006) 
           {
    		   cout << "Really? What day?\n" << endl;
    		   cin >> DATE;
    		   cin.ignore();
    	   }
    	   else if (DOB == 2006) 
           {
    		   cout << "Really? How old are you?\n" << endl;
    		   cin >> AGE;
    		   cout << "...and what month?\n" << endl;
    		   cin >> MONTH;
    		   cin.ignore();
    	   }
    	   else 
           {
    		   cout << "What are you on about? You arn't even born yet!\n" << endl;
    	   }
       }
       while(DOB != -1);          
       cin.get();      
    }
    can anyone help me?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,758
    i get to a certain point where the program sort of goes out of control
    How does it not work?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321
    i don't know, u key it in ur compiler nd run it, when you get to the date part, i type in 17th or sumfin nd it goes out of control.

  4. #4
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    don't use 'th' with ints. Check the FAQ. This may be of interest.

    You could store it in a string, and only get the integer parts, and ignore the other letters. That is if you want to have the 'th' acceptable to the input.

  5. #5
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321
    i fixed it, but i used char[4] instead

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strange bug with Input stream
    By Chazij in forum C++ Programming
    Replies: 12
    Last Post: 11-18-2008, 03:52 PM
  2. Strange bug with DevCPP v 4.9.9.2
    By domhnall4h in forum C++ Programming
    Replies: 4
    Last Post: 03-13-2006, 06:10 AM
  3. Strange Bug?
    By okinrus in forum C++ Programming
    Replies: 3
    Last Post: 07-07-2004, 01:00 PM
  4. Very strange bug...
    By JaWiB in forum Tech Board
    Replies: 6
    Last Post: 04-27-2003, 01:56 PM
  5. Very Strange Bug
    By Asm_Freak in forum C++ Programming
    Replies: 0
    Last Post: 02-09-2003, 10:04 PM

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