C
C#14mo ago
Ewan

✅ Help with my program please!

Ok so for this program im making, I want the user to input a number (e.g. 15) and then the words fizz, buzz and fizzbuzz to be printed. The number inputted is what the program will go up to so if 15 was inputted then it would check numbers 1 to 15 Fizz for every number divisible by 3 Buzz for every number divisible by 5 And Fizzbuzz for every number divisible by 5 and 3 Then output on the last line of my code how many times it has said fizz, buzz, fizzbuzz and also how many numbers have been printed which arent divisible by 3 and 5. however on the last line, every time i run the program all the numbers printed are the same e.g. 5,5,5,5 why? Help please!
No description
13 Replies
Angius
Angius14mo ago
Because you tried writing Python
Ewan
EwanOP14mo ago
AAAh
Angius
Angius14mo ago
Braces are important
Ewan
EwanOP14mo ago
im too used to python new to this!
Angius
Angius14mo ago
Braceless statements only use the line that immediately follows
Ewan
EwanOP14mo ago
how would i use brackets here? oh i see so would i have both lines of each if statement in brackets?
Angius
Angius14mo ago
So
if (1 == 1)
Write("a");
Write("b");
if (2 == 2)
Write("c");
Write("d");
if (1 == 1)
Write("a");
Write("b");
if (2 == 2)
Write("c");
Write("d");
is the same as
if (1 == 1)
{
Write("a");
}
Write("b");
if (2 == 2)
{
Write("c");
}
Write("d");
if (1 == 1)
{
Write("a");
}
Write("b");
if (2 == 2)
{
Write("c");
}
Write("d");
You need to put everything that's supposed to be handled by a given branch into the braces
Ewan
EwanOP14mo ago
oh my god it worked
Angius
Angius14mo ago
So
if (1 == 1)
{
Write("a");
Write("b");
}
if (2 == 2)
{
Write("c");
Write("d");
}
if (1 == 1)
{
Write("a");
Write("b");
}
if (2 == 2)
{
Write("c");
Write("d");
}
Ewan
EwanOP14mo ago
thank yay
Angius
Angius14mo ago
Anytime Ok
Ewan
EwanOP14mo ago
!close
Accord
Accord14mo ago
Closed!
Want results from more Discord servers?
Add your server