Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8841603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:45:38+00:00 2026-06-14T10:45:38+00:00

I wanted to test my C++ skills by hammering out a quick fizzbuzz application.

  • 0

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.
Compiled, ran, and ls
Remainder of ls command

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:45:40+00:00Added an answer on June 14, 2026 at 10:45 am

    As other commenters have said, output = i is the issue here. The value of i casts from an int to a char, leaving the output string with a sequence ASCII characters when you run that loop. For example, 97 == 'a', 144 == 'É', and so on.

    I would consider rewriting the logic in the main function to simply have three cout << ... calls inside an if-else block. Additionally, the ismultipleN() functions can be replaced with simply (i % 3 == 0) for brevity.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanted to quick test a small snippet of PHP code. So, After doing
A simple question. Does this version support generators? I wanted to test out using
Out of curiosity I wanted to test the number of ticks to compare a
I have built part of my app and wanted to test it out. All
I have a console application that utilizes the BackgroundWorker object and wanted to test
I have some error correcting code, and I wanted to test to make sure
I wanted to test the following code (which works fine for a non-null list)
I wanted to test Mono AOT, so I wrote a simple console application with
I wanted to test how long it takes a method to run and I
While reading this question I wanted to test the input in GCC to see

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.