Discuss Scratch
- Discussion Forums
- » Things I'm Making and Creating
- » C++ Official Topic
- tingtong2
- Scratcher
100+ posts
C++ Official Topic
Hey guys! I made some stuff in c++ using what my teacher taught us so here it is!
Here's the one I did around 3 months ago.
And the one below I made yesterday and a bit today!
input:
output:
Please give suggestions on how to make this better and also what I could try next!
Here's the one I did around 3 months ago.
And the one below I made yesterday and a bit today!
input:
output:
Please give suggestions on how to make this better and also what I could try next!
Press Shift and down arrow to see my full signature
See this Video! https://scratch.mit.edu/discuss/youtube/N6t6QHQtdVw/ It's to stop Climate Change something we kids should stop this!
See these 2 forums I made for people learning French and/or German so you can chat and practice that language!
Go to my profile (here) and please say “hi” or something else cause I'm board, and I don't get messages
See "Mini Scratch" Give song suggestions for Mini Scratch over here
Please see iTingOS 2.0 (the best OS that's shared of mine) If you like it, please star and heart it..!
See this forum and this project which I talked about in the forum
To New Scratchers
You're lucky to know about forums, I only knew about it when, I was on Scratch for around 5 months
Have nice time learning about scratch…
To Everyone
Scratch is about coding and having fun, not for followers and/or fame
Scratch Out, Scratch High, Scratch Beyond
(inspired by my old school)
@tingtong2 is going out..
- Vaibhs11
- Scratcher
1000+ posts
C++ Official Topic
There's not much to improve, just that you can declare all data first then the rest of the code for uhh… obvious reasons. Please give suggestions on how to make this better and also what I could try next!
For more ideas, I suggest rather finish learning c++ first. There's much more to it than console I/O
- CT-7569
- Scratcher
100+ posts
C++ Official Topic
I'm trying to make a Celsius and Fahrenheit table in C++:
For some reason, the Fahrenheit values aren't accurate though:
Can someone help?
#include <iostream> using namespace std; int main() { double fahr; for (int celsius = -40; celsius < 101; celsius++) { fahr = ((celsius * 9) / 5) + 32; cout << to_string(celsius) << " = " << to_string(fahr) + "\n"; } return 0; }
For some reason, the Fahrenheit values aren't accurate though:
-40 = -40.000000
-39 = -38.000000
-38 = -36.000000
-37 = -34.000000
-36 = -32.000000
-35 = -31.000000
-34 = -29.000000
-33 = -27.000000
-32 = -25.000000
-31 = -23.000000
-30 = -22.000000
-29 = -20.000000
-28 = -18.000000
-27 = -16.000000
-26 = -14.000000
-25 = -13.000000
-24 = -11.000000
-23 = -9.000000
-22 = -7.000000
-21 = -5.000000
-20 = -4.000000
-19 = -2.000000
-18 = 0.000000
-17 = 2.000000
-16 = 4.000000
-15 = 5.000000
-14 = 7.000000
-13 = 9.000000
-12 = 11.000000
-11 = 13.000000
-10 = 14.000000
-9 = 16.000000
-8 = 18.000000
-7 = 20.000000
-6 = 22.000000
-5 = 23.000000
-4 = 25.000000
-3 = 27.000000
-2 = 29.000000
-1 = 31.000000
0 = 32.000000
1 = 33.000000
2 = 35.000000
3 = 37.000000
4 = 39.000000
5 = 41.000000
6 = 42.000000
7 = 44.000000
8 = 46.000000
9 = 48.000000
10 = 50.000000
11 = 51.000000
12 = 53.000000
13 = 55.000000
14 = 57.000000
15 = 59.000000
16 = 60.000000
17 = 62.000000
18 = 64.000000
19 = 66.000000
20 = 68.000000
21 = 69.000000
22 = 71.000000
23 = 73.000000
24 = 75.000000
25 = 77.000000
26 = 78.000000
27 = 80.000000
28 = 82.000000
29 = 84.000000
30 = 86.000000
31 = 87.000000
32 = 89.000000
33 = 91.000000
34 = 93.000000
35 = 95.000000
36 = 96.000000
37 = 98.000000
38 = 100.000000
39 = 102.000000
40 = 104.000000
41 = 105.000000
42 = 107.000000
43 = 109.000000
44 = 111.000000
45 = 113.000000
46 = 114.000000
47 = 116.000000
48 = 118.000000
49 = 120.000000
50 = 122.000000
51 = 123.000000
52 = 125.000000
53 = 127.000000
54 = 129.000000
55 = 131.000000
56 = 132.000000
57 = 134.000000
58 = 136.000000
59 = 138.000000
60 = 140.000000
61 = 141.000000
62 = 143.000000
63 = 145.000000
64 = 147.000000
65 = 149.000000
66 = 150.000000
67 = 152.000000
68 = 154.000000
69 = 156.000000
70 = 158.000000
71 = 159.000000
72 = 161.000000
73 = 163.000000
74 = 165.000000
75 = 167.000000
76 = 168.000000
77 = 170.000000
78 = 172.000000
79 = 174.000000
80 = 176.000000
81 = 177.000000
82 = 179.000000
83 = 181.000000
84 = 183.000000
85 = 185.000000
86 = 186.000000
87 = 188.000000
88 = 190.000000
89 = 192.000000
90 = 194.000000
91 = 195.000000
92 = 197.000000
93 = 199.000000
94 = 201.000000
95 = 203.000000
96 = 204.000000
97 = 206.000000
98 = 208.000000
99 = 210.000000
100 = 212.000000
Can someone help?
–CT-7569
- tingtong2
- Scratcher
100+ posts
C++ Official Topic
I meant to ask if I could do more C++ itself, which I know I can. There's not much to improve, just that you can declare all data first then the rest of the code for uhh… obvious reasons.
For more ideas, I suggest rather finish learning c++ first. There's much more to it than console I/O
Press Shift and down arrow to see my full signature
See this Video! https://scratch.mit.edu/discuss/youtube/N6t6QHQtdVw/ It's to stop Climate Change something we kids should stop this!
See these 2 forums I made for people learning French and/or German so you can chat and practice that language!
Go to my profile (here) and please say “hi” or something else cause I'm board, and I don't get messages
See "Mini Scratch" Give song suggestions for Mini Scratch over here
Please see iTingOS 2.0 (the best OS that's shared of mine) If you like it, please star and heart it..!
See this forum and this project which I talked about in the forum
To New Scratchers
You're lucky to know about forums, I only knew about it when, I was on Scratch for around 5 months
Have nice time learning about scratch…
To Everyone
Scratch is about coding and having fun, not for followers and/or fame
Scratch Out, Scratch High, Scratch Beyond
(inspired by my old school)
@tingtong2 is going out..
- Vaibhs11
- Scratcher
1000+ posts
C++ Official Topic
Simple, replace 9/5 with 1.8 and you also don't need double for this table. Can someone help?
#include <iostream> using namespace std; int main() { float fahr; for (int celsius = -40; celsius < 101; celsius++) { fahr = (celsius * 1.8) + 32; cout << to_string(celsius) << " = " << to_string(fahr) + "\n"; } return 0; }
- CT-7569
- Scratcher
100+ posts
C++ Official Topic
(#105)Thanks! What's the difference between float and double? On W3Schools it says double is used for floating point numbers. Also, why didn't it work when I put ((celsius * 9) / 5)?Simple, replace 9/5 with 1.8 and you also don't need double for this table. Can someone help?
–snip–
Last edited by CT-7569 (Oct. 25, 2022 06:22:59)
–CT-7569
- pkhead
- Scratcher
1000+ posts
C++ Official Topic
a double takes up 64 bits, while a float takes up 32 bits. because of the added bits, a double is more precise than a float.(#105)Thanks. What's the difference between float and double? On W3Schools it says double is used for floating point numbers. Also, why didn't it work when I put ((celsius * 9) / 5)?Simple, replace 9/5 with 1.8 and you also don't need double for this table. Can someone help?
–snip–
~ pumpkinhead
Hi, I'm a pumpkinhead. Did you know that kumquats have rights? The constitution says they do, and so do I. I believe that until proven one has eaten a signature on the forums of the website at scratch.mit.edu, connected to with the HTTPS protocol, every kumquat, kumquette, and kumqi in this country is innocent.
fuzzy jumpscare BOO!!!!
- pkhead
- Scratcher
1000+ posts
C++ Official Topic
and also putting ((celsius * 9) / 5) didn’t work because celsius is an int, and doing division with and int and an int will round the value down. for example, (int)5 / (int)3 would equal to (int)1, but (int)5 / (double)3.0 would equal to (double)1.666666667,(#105)Thanks. What's the difference between float and double? On W3Schools it says double is used for floating point numbers. Also, why didn't it work when I put ((celsius * 9) / 5)?Simple, replace 9/5 with 1.8 and you also don't need double for this table. Can someone help?
–snip–
multiplying an int by a double, which celsius * 1.8 does, will output a double.
Last edited by pkhead (Oct. 23, 2022 14:37:19)
~ pumpkinhead
Hi, I'm a pumpkinhead. Did you know that kumquats have rights? The constitution says they do, and so do I. I believe that until proven one has eaten a signature on the forums of the website at scratch.mit.edu, connected to with the HTTPS protocol, every kumquat, kumquette, and kumqi in this country is innocent.
fuzzy jumpscare BOO!!!!
- CT-7569
- Scratcher
100+ posts
C++ Official Topic
(#108)Thanks!–snip–and also putting ((celsius * 9) / 5) didn’t work because celsius is an int, and doing division with and int and an int will round the value down. for example, (int)5 / (int)3 would equal to (int)1, but (int)5 / (double)3.0 would equal to (double)1.666666667,
multiplying an int by a double, which celsius * 1.8 does, will output a double.
–CT-7569
- GIitchInTheMatrix
- Scratcher
1000+ posts
C++ Official Topic
#include <iostream> Int main(){ for (int pagenumber < 50; pagenumber < 1; pagenumber++){ //i think this is the right order for a for loop, and i think this is on page 50. And i don’t think int is in the standard library std::cout<<“BUMP”; } }
- pkhead
- Scratcher
1000+ posts
C++ Official Topic
Oh no#include <iostream> Int main(){ for (int pagenumber < 50; pagenumber < 1; pagenumber++){ //i think this is the right order for a for loop, and i think this is on page 50. And i don’t think int is in the standard library std::cout<<“BUMP”; } }
src.cpp:4:16: error: extended character “ is not valid in an identifier
4 | std::cout<<“BUMP”;
| ^
src.cpp:4:16: error: extended character ” is not valid in an identifier
src.cpp:2:1: error: 'Int' does not name a type; did you mean 'int'?
2 | Int main(){
| ^~~
| int
~ pumpkinhead
Hi, I'm a pumpkinhead. Did you know that kumquats have rights? The constitution says they do, and so do I. I believe that until proven one has eaten a signature on the forums of the website at scratch.mit.edu, connected to with the HTTPS protocol, every kumquat, kumquette, and kumqi in this country is innocent.
fuzzy jumpscare BOO!!!!
- GIitchInTheMatrix
- Scratcher
1000+ posts
C++ Official Topic
Thats why you always write code in an IDE before posting it. Even that joke.Oh no#include <iostream> Int main(){ for (int pagenumber < 50; pagenumber < 1; pagenumber++){ //i think this is the right order for a for loop, and i think this is on page 50. And i don’t think int is in the standard library std::cout<<“BUMP”; } }src.cpp:4:16: error: extended character “ is not valid in an identifier
4 | std::cout<<“BUMP”;
| ^
src.cpp:4:16: error: extended character ” is not valid in an identifier
src.cpp:2:1: error: 'Int' does not name a type; did you mean 'int'?
2 | Int main(){
| ^~~
| int
- pkhead
- Scratcher
1000+ posts
C++ Official Topic
yes, this is the internet, be wary of pedantic code checkers. and also, you don't need an IDE, i just copied it into a file and used command line GCC to check the syntax errors. and also be wary of pedantic terminology usage checkers on the Internet. very dangerous.Thats why you always write code in an IDE before posting it. Even that joke.Oh no#include <iostream> Int main(){ for (int pagenumber < 50; pagenumber < 1; pagenumber++){ //i think this is the right order for a for loop, and i think this is on page 50. And i don’t think int is in the standard library std::cout<<“BUMP”; } }src.cpp:4:16: error: extended character “ is not valid in an identifier
4 | std::cout<<“BUMP”;
| ^
src.cpp:4:16: error: extended character ” is not valid in an identifier
src.cpp:2:1: error: 'Int' does not name a type; did you mean 'int'?
2 | Int main(){
| ^~~
| int
~ pumpkinhead
Hi, I'm a pumpkinhead. Did you know that kumquats have rights? The constitution says they do, and so do I. I believe that until proven one has eaten a signature on the forums of the website at scratch.mit.edu, connected to with the HTTPS protocol, every kumquat, kumquette, and kumqi in this country is innocent.
fuzzy jumpscare BOO!!!!
- QueenKyttySparkle
- Scratcher
100+ posts
C++ Official Topic
Hello! I am a Python coder who is starting to learn C++. Some tips would be appreciated!
My browser: Chrome (No flash version & Always updated) My os: Windows 11. My timezone: BST/GMT (London)
Scratch | Studio
Hello! Want to see more? Then select this text, hold shift and press the down arrow!
Welcome to my signature!!
Dang, 100 posts!
Unofficial forum helper.
Stop having a go at me for making a duplicate topic, letting me know is fine but don't blame me. I can't take it :(
Heads up, I love writing essays on my opinions.
Well more like heads down.. cause it's below the actual post..
- GIitchInTheMatrix
- Scratcher
1000+ posts
C++ Official Topic
Get ready to the standard library a lot. Hello! I am a Python coder who is starting to learn C++. Some tips would be appreciated!
Do not directly declare the namespace, do namespace::fun instead.
Use only libraries you will need.
Also, coffee.
Last edited by GIitchInTheMatrix (April 25, 2023 16:01:21)
- QueenKyttySparkle
- Scratcher
100+ posts
C++ Official Topic
Gotta love that rich bitter taste of coffee Also, coffee.
My browser: Chrome (No flash version & Always updated) My os: Windows 11. My timezone: BST/GMT (London)
Scratch | Studio
Hello! Want to see more? Then select this text, hold shift and press the down arrow!
Welcome to my signature!!
Dang, 100 posts!
Unofficial forum helper.
Stop having a go at me for making a duplicate topic, letting me know is fine but don't blame me. I can't take it :(
Heads up, I love writing essays on my opinions.
Well more like heads down.. cause it's below the actual post..
- -cloudcoding-
- Scratcher
1000+ posts
C++ Official Topic
I kinda hate c (im not necroposting)
Last edited by kaj (Tomorrow 00:00:00)
-cloudcoding-
"[coding is] like clouds - always evolving and ready to transform!" - ChatGPT :)
Go check out my projects!
- DifferentDance8
- Scratcher
1000+ posts
C++ Official Topic
Then why post in a topic about a descendant of C? I kinda hate c (im not necroposting)
=
I know pretty much the basic “hello world” and nothing else.
Mod's Protogen Maker v2 released. I will update it when I will update it
- GIitchInTheMatrix
- Scratcher
1000+ posts
C++ Official Topic
Well, my recent coffee addiction is ironic.Gotta love that rich bitter taste of coffee Also, coffee.
-Stephen
- QueenKyttySparkle
- Scratcher
100+ posts
C++ Official Topic
o__oWell, my recent coffee addiction is ironic.Gotta love that rich bitter taste of coffee Also, coffee.
-Stephen
My browser: Chrome (No flash version & Always updated) My os: Windows 11. My timezone: BST/GMT (London)
Scratch | Studio
Hello! Want to see more? Then select this text, hold shift and press the down arrow!
Welcome to my signature!!
Dang, 100 posts!
Unofficial forum helper.
Stop having a go at me for making a duplicate topic, letting me know is fine but don't blame me. I can't take it :(
Heads up, I love writing essays on my opinions.
Well more like heads down.. cause it's below the actual post..
- Discussion Forums
- » Things I'm Making and Creating
- » C++ Official Topic