0
How in the hot pocket do I get my C++ code working
making it myself? Didn't work, trying to memorize something? Nope, literally copy and paste? Still errors
8 ответов
+ 1
Mira Hedman
First you need to understand the basics of how c++ works so hopefully you're doing the lessons😁
Here's a very simple game. It generates a random number between 1 and 3. You run the program, when the dialog box opens enter your guess and submit. The output will tell you if you win or lose.
https://code.sololearn.com/cMxr3hkkEE5b/?ref=app
+ 1
Mira Hedman
What code? What are you trying to do?
+ 1
Mira Hedman
C++ is a programming language so if you want it to do something for you then you need to know how to "talk" to it and give it instructions. Have you started the lessons yet?
https://www.sololearn.com/Course/CPlusPlus/?ref=app
In your code you are using cout which is an instruction for it to print something but that's it. So it will not do anything else. Start slow, it will come quickly though if you practice.
So you know cout will print, now learn how to use cin.
cin asks for input. cout will print the output.
0
Scott D like a simple game like if you run it there is a chance that you lose or win
0
Mira Hedman
Here's another. Same game but more like a slot machine. You don't need to enter anything. Just run it. It generates two random numbers between 1 & 3. If they match you win.
https://code.sololearn.com/caZ9GD37k84h/?ref=app
0
Mira Hedman
Here's an example of cin and cout.
Then you need to learn the difference between how c++ deals with different information.
string - used for words and sentences etc.
int - used for integers (whole numbers that don't have decimals like 4 or 312)
Here's an example of using cin and cout.
https://code.sololearn.com/chVw9jOa5030/?ref=app
0
Mira Hedman
Here's another example. There are now other instructions to tell the program to add together 2 numbers (integers). This code lets you enter a number then adds 10 and prints it. Try altering the code to add 20 to the number you enter.
Try some lessons. If you have questions ask me or the discuss forum. And learning how to alter code is good practice. So for example with the game I posted, save a copy. Leave in the code, but change only the cout statement to print something like "Sorry, wrong guess" and "You're a winner! "
But the other code is the instructions to c++ to perform the game. If you remove it and only have cout then the code doesn't know what it should do except to print something.
Again, do the lessons. It doesn't take long. I've only been doing this for a few weeks. And it becomes more fun as soon as you learn how to tell c++ how to do what you want it to.
Feel free to play with other code like mine just to see what it does.
https://code.sololearn.com/cP0l31LiDG7L/?ref=app
- 1
https://code.sololearn.com/cgs7UNFxR127/?ref=app