I'm relatively new to stack overflow (yes, i'm extremely new to coding), and i'm currently working on an altered version of the Fizz Buzz Question. Could someone help me figure out as to what i'm doing wrong? I can't seem to find the answer on Stack Overflow. Use a while loop instead of for loop to write a program that outputs the string representation of numbers from 1 to n.
But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. For numbers which are multiples of both three and five output “FizzBuzz”.
Example:
n = 15,
Output:
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
My code is
#include <iostream>
using namespace std;
int n = 0;
{
cout << "Enter your number "; // Prompt for input
cin >> n; // Get the input.
for (int i = 1; i <= n; i++)
{
if ((i % 15) == 0)
cout << "FizzBuzz\n";
else if ((i % 3) == 0)
cout << "Fizz\n";
else if ((i % 5) == 0)
cout << "Buzz\n";
else
cout << i << "\n";
}
return 0;
}
While I am receiving the error for line 4:
4:1: error: expected ',' or ';' before '{' token