Results 1 to 4 of 4

Thread: Something wrong with my loop..

  1. #1

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Something wrong with my loop..

    // function example
    #include <iostream>
    #include <ctime>
    #include <cstdlib>
    using namespace std;

    Code:
    int main ()
    {
    	int me;
    	int comp;
    	int explode;
    
    	srand((unsigned)time(0));//uses ctime to pick a semi random number
    	comp = (rand()%11)+1;
    		me = 5;
    
    			do{
    				me = me - 1;
    				cout << me <<" Tries left; " << "Try and guess which number!: ";
    					cin >> explode;
    					if(explode=comp){
    						break;
    					}
    			}while (me > 0);
    	
    system( "pause" );
    return 0;
    }
    instead of asking you to type the number you think it is until you get it, on keypress it ends...any idea?

  2. #2

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Something wrong with my loop..

    if(explode==comp){

    why though?

  3. #3
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Re: Something wrong with my loop..

    because unlike VB there is a difference between the assignment operator (=), and the comparason operator (==).

    The assignment operator assignes the value on the right hand side, to the left hand side, then returns the result (which was being checked by the if statement).

    The comparason operator just returns whether they're equal or not.


    BTW. i strongly recommend you check out CornedBee's tutorials, they'd be a great help to get you started. I believe he gave you the address in on of his replies to another of your threads.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  4. #4
    Addicted Member
    Join Date
    Jul 2003
    Posts
    255

    Re: Something wrong with my loop..

    It would also be easier to use a for loop in this instance, not a do...while, and you should really not use system() calls or namespaces.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width