I wanted to test my C++ skills by hammering out a quick fizzbuzz application. The code for it is posted below. However, when I run this application, something crazy occurs. Here's my code:
#include <iostream>
#include <string>
using namespace std;
bool ismultiple3(int i) {
int res = i%3;
if (res == 0)
return true;
return false;
}
bool ismultiple5(int i) {
int res = i%5;
if (res == 0)
return true;
return false;
}
int main() {
string output;
for (int i = 1; i <= 100; i++) {
output = i;
if (ismultiple5(i) || ismultiple3(i)) {
output = "";
if (ismultiple3(i)) output.append("Fizz");
if (ismultiple5(i)) output.append("Buzz");
}
cout << output;
}
}
So when I run and compile it, my whole terminal gets messed up. It seems like the character encoding is somehow being altered. It still accepts commands normally, it just looks off. I ran an ls to demonstrate this.
Edit: In case anyone runs across this, I ended up adding an else statement and doing cout << i
in it, because my computer's g++ compiler lacked C++11 support. The functions were also shortened and combined into a single function that accepts 2 arguments, i
and n
.