How in the hot pocket do I get my C++ code working | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

24th Nov 2022, 7:40 PM
Mira Hedman
Mira Hedman - avatar
8 Answers
+ 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
25th Nov 2022, 6:15 AM
Scott D
Scott D - avatar
+ 1
Mira Hedman What code? What are you trying to do?
24th Nov 2022, 10:21 PM
Scott D
Scott D - avatar
+ 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.
25th Nov 2022, 8:56 PM
Scott D
Scott D - avatar
0
Scott D like a simple game like if you run it there is a chance that you lose or win
25th Nov 2022, 5:36 AM
Mira Hedman
Mira Hedman - avatar
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
25th Nov 2022, 6:24 AM
Scott D
Scott D - avatar
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
25th Nov 2022, 9:15 PM
Scott D
Scott D - avatar
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
25th Nov 2022, 9:43 PM
Scott D
Scott D - avatar
- 1
https://code.sololearn.com/cgs7UNFxR127/?ref=app
25th Nov 2022, 3:31 PM
Mira Hedman
Mira Hedman - avatar