Discuss Scratch

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!

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

tingtong2 wrote:

Please give suggestions on how to make this better and also what I could try next!
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
CT-7569
Scratcher
100+ posts

C++ Official Topic

I'm trying to make a Celsius and Fahrenheit table in C++:
#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

Vaibhs11 wrote:

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
I meant to ask if I could do more C++ itself, which I know I can.

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

CT-7569 wrote:

Can someone help?
Simple, replace 9/5 with 1.8 and you also don't need double for this table.
#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

Vaibhs11 wrote:

(#105)

CT-7569 wrote:

Can someone help?
Simple, replace 9/5 with 1.8 and you also don't need double for this table.

–snip–

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)?

Last edited by CT-7569 (Oct. 25, 2022 06:22:59)


–CT-7569
pkhead
Scratcher
1000+ posts

C++ Official Topic

CT-7569 wrote:

Vaibhs11 wrote:

(#105)

CT-7569 wrote:

Can someone help?
Simple, replace 9/5 with 1.8 and you also don't need double for this table.

–snip–

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)?
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.
pkhead
Scratcher
1000+ posts

C++ Official Topic

CT-7569 wrote:

Vaibhs11 wrote:

(#105)

CT-7569 wrote:

Can someone help?
Simple, replace 9/5 with 1.8 and you also don't need double for this table.

–snip–

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)?
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.

Last edited by pkhead (Oct. 23, 2022 14:37:19)

CT-7569
Scratcher
100+ posts

C++ Official Topic

pkhead wrote:

(#108)

CT-7569 wrote:

–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.
Thanks!

–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;
  }
}

this is my signature
I have exactly 8934 posts
pkhead
Scratcher
1000+ posts

C++ Official Topic

GIitchInTheMatrix wrote:

#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;
  }
}
Oh no
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
GIitchInTheMatrix
Scratcher
1000+ posts

C++ Official Topic

pkhead wrote:

GIitchInTheMatrix wrote:

#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;
  }
}
Oh no
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
Thats why you always write code in an IDE before posting it. Even that joke.

this is my signature
I have exactly 8934 posts
pkhead
Scratcher
1000+ posts

C++ Official Topic

GIitchInTheMatrix wrote:

pkhead wrote:

GIitchInTheMatrix wrote:

#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;
  }
}
Oh no
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
Thats why you always write code in an IDE before posting it. Even that joke.
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.
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

QueenKyttySparkle wrote:

Hello! I am a Python coder who is starting to learn C++. Some tips would be appreciated!
Get ready to the standard library a lot.
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)


this is my signature
I have exactly 8934 posts
QueenKyttySparkle
Scratcher
100+ posts

C++ Official Topic

GIitchInTheMatrix wrote:

Also, coffee.
Gotta love that rich bitter taste of 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

-cloudcoding- wrote:

I kinda hate c (im not necroposting)
Then why post in a topic about a descendant of C?
=
I know pretty much the basic “hello world” and nothing else.

i might recreate my pfp in Mod's Protogen Maker v2 if- i mean when it releases
GIitchInTheMatrix
Scratcher
1000+ posts

C++ Official Topic

QueenKyttySparkle wrote:

GIitchInTheMatrix wrote:

Also, coffee.
Gotta love that rich bitter taste of coffee
Well, my recent coffee addiction is ironic.
-Stephen

this is my signature
I have exactly 8934 posts
QueenKyttySparkle
Scratcher
100+ posts

C++ Official Topic

GIitchInTheMatrix wrote:

QueenKyttySparkle wrote:

GIitchInTheMatrix wrote:

Also, coffee.
Gotta love that rich bitter taste of coffee
Well, my recent coffee addiction is ironic.
-Stephen
o__o

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..

Powered by DjangoBB