Renkia Posted May 10, 2010 Share Posted May 10, 2010 Hey Makewebgames/MCC Forum: I Was on the (C++) website, learning C++ of course. But, there a problem I can't get my head around. Allow me to put a lower, description: The input!: // i/o example #include <iostream> using namespace std; int main(){ int i; cout << "Please choose a random number!"; cin >> i; cout << the nuber you have choosen is << i; cout << "and its double is " << i*2 << ".\n"; return 0;} The output!: Please choose a random number! 702 the value you entered is 702 and its double is 1404. Now, it doesn't explain how on http://www.cplusplus.com how ( i; ) is the number 702? Its really gotten on my mind, all day. I Have set the syntax right, it doesn't appear right thou, sorry. Thanks, for reading Rasheed Saeed (Renkia) Quote Link to comment Share on other sites More sharing options...
Djkanna Posted May 10, 2010 Share Posted May 10, 2010 Notice: cin >> i; Well the istream object cin generally gets the users input cin C++ Reference Quote Link to comment Share on other sites More sharing options...
Spudinski Posted May 10, 2010 Share Posted May 10, 2010 Well, as "c out" is the default print/output function, "c in" is the default input function(how I remember it). But someone more proficient explains... http://stackoverflow.com/questions/1080805/c-how-does-sleep-and-cin-work Quote Link to comment Share on other sites More sharing options...
Zeggy Posted May 10, 2010 Share Posted May 10, 2010 cin >> i; That line takes a number from standard input (your keyboard) and puts it in the variable i. Quote Link to comment Share on other sites More sharing options...
Renkia Posted May 11, 2010 Author Share Posted May 11, 2010 Wait! So it just wont take (702) all the time? Just random numbers? Quote Link to comment Share on other sites More sharing options...
Zeggy Posted May 11, 2010 Share Posted May 11, 2010 It takes whatever number you enter into the program after you run it. Quote Link to comment Share on other sites More sharing options...
Spudinski Posted May 11, 2010 Share Posted May 11, 2010 No, it takes your direct input and assigns it to the i variable. For instance, if a process is waiting for input from the console, the OS can look at the processes information and see which io ports its waiting for. It can check those ports to see if they have any data for the process to work on. If they do, it can start the process up again, but if there is no data, then that process gets skipped over for the current timeslice. To explain that in human terms: The process actually waits, to get the user input. And then continues to follow the set of rules you defined(the program). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.