C
C#8mo 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
Angius8mo ago
Because you tried writing Python
Ewan
Ewan8mo ago
AAAh
Angius
Angius8mo ago
Braces are important
Ewan
Ewan8mo ago
im too used to python new to this!
Angius
Angius8mo ago
Braceless statements only use the line that immediately follows
Ewan
Ewan8mo ago
how would i use brackets here? oh i see so would i have both lines of each if statement in brackets?
Angius
Angius8mo 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
Ewan8mo ago
oh my god it worked
Angius
Angius8mo 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
Ewan8mo ago
thank yay
Angius
Angius8mo ago
Anytime Ok
Ewan
Ewan8mo ago
!close
Accord
Accord8mo ago
Closed!