|
-
May 18th, 2005, 04:10 PM
#1
Thread Starter
Admodistrator
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?
-
May 18th, 2005, 04:51 PM
#2
Thread Starter
Admodistrator
Re: Something wrong with my loop..
if(explode==comp){
why though?
-
May 18th, 2005, 06:01 PM
#3
Not NoteMe
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. 
-
May 18th, 2005, 06:04 PM
#4
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|