hi everybody! I'm new to programing in C++.
I have a question..How I can assign to "x" values beetween 0 and 10.
I can make " int 0<x<10;" or "int x=1,2,3,4,5,6,7,8,9;" or...
please help me
hi everybody! I'm new to programing in C++.
I have a question..How I can assign to "x" values beetween 0 and 10.
I can make " int 0<x<10;" or "int x=1,2,3,4,5,6,7,8,9;" or...
please help me
Try a for loop.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
This displays numbers from 0 to 10.
If you want it to go from 1 to 10 just change "int x = 0" to "int x = 1".
Code:#include <iostream> using namespace std; int main() { for (int x=0; x<=10; x++) { cout << x << endl; } return 0; }
I want to make a small game ..to guess the number beetween 1 an 10. I don't want to show the numbers 1,2,3...10. I know woh to make that . so?
search up:
-if statements
-cin
edit: also you will need rand()
I'm new to C++ and I consider myself a complete dunce when it comes to this language, but curiosity got the better of me and decided to give this a go, (even though I guess this will do the homework for the original poster).
It took me a while to figure out how rand() worked, but coming from nothing to the above in 30 minutes is nothing less than amazing to me.Code:#include <iostream> #include <stdlib.h> #include topsecret using namespace std; int main () { int number = 0, guess = 0; srand ( somemagic ); number = rand() % fairydust; cout << "I'm thinking of a number. Can you guess which?" << endl; while (guess != guesswhat) { cout << "Pick a number : "; cin >> guess; if (number > guess) cout << "Too low" << endl; else if (number < guess) cout << "Too high" << endl; else cout << "You're a genious!" << endl; } }
Last edited by slartie; 10-17-2011 at 01:02 PM. Reason: obscuring a few obvious parts of the code