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 8122589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:52:53+00:00 2026-06-06T05:52:53+00:00

I am having trouble passing the return value from TheMethod() to Main and displaying

  • 0

I am having trouble passing the return value from TheMethod() to Main and displaying the word if the if statement is passed as true.

I have thought of two ways of doing this, neither has worked but I think I am missing synatx.

  1. Using a return ?; non void method and then displaying the returned value.
  2. Using a void method and actually writing out(example below)

So yes I am new at this, however I have made so many iterations everything is blending together and I have forgot what I have tried. Any help on the syntax be great for either of these ways.

Basically I need it to iterate numbers

1,2,3,4 and depending on if the current iteration matches an expression in the if statements it will display a word.

Example:

if (3 = i)
{
   Console.WriteLine("Word");
}

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Proj5
{
class Program
{
    int i = 0;



    static void Main(int i)
    {

        for (i = 0; i < 101; i++)
        {

            Console.WriteLine("test");
        }
    }

    string TheMethod(int i)
    {
        string f = "Word1";
        string b = "Word2";


        if (i == 3)
        {
            return f;
        }

        if (i == 5)
        {
            return b;
        }

        if (0 == (i % 3))
        {
            return f;
        }

        if (0 == i % 5)
        {
            return b;
        }
        else
        {
            return b;
        }

    }
}
}
  • 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-06T05:52:55+00:00Added an answer on June 6, 2026 at 5:52 am

    Note: You don’t need if i == 5 and a separate one for i % 5 == 0. % is “mod” which means the remainder after the division, so 5 / 5 = 1, there is no remainder so 5 mod 5 = 0…

    Here is a rough guide/fix for you attempt at FizzBuzz:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace Proj5
    {
    class Program
    {
        private static void Main()
        {
            for (int i = 0; i < 101; i++)
            {
                Console.WriteLine(TheMethod(i));
            }
        }
    
        string TheMethod(int i)
        {
            string f = "Fizz";
            string b = "Buzz";
    
            if ((i % 3 == 0) && (i % 5 == 0))
            {
                return f+b;
            }
            if (i % 3 == 0)
            {
                return f;
            }
    
            if (i % 5 == 0)
            {
                return b;
            }
    
            return i.ToString();
    
        }
    }
    }
    

    However there are cleaner solutions:

    string result = "";
    for (int i = 1; i < = 101; ++i)
    {
        if ((i % 3 == 0) && (i % 5 == 0)) result += "FizzBuzz";
        else if (i % 3 == 0) result += "Fizz";
        else if (i % 5 == 0) result += "Buzz";
        else result += i.ToString();
        result += ", ";
    }
    

    Or, if you prefer LINQ-y Lambas:

    public static void FizzBuzz()
    {
        Dictionary<Func<int, bool>, Func<int, string>> rules = new Dictionary<Func<int, bool>, Func<int, string>>();
        rules.Add(x => x % 5 == 0 && x % 3 == 0, x => “fizzbuzz”);
        rules.Add(x => x % 3 == 0, x => "fizz");
        rules.Add(x => x % 5 == 0, x => "buzz");
        rules.Add(x => x % 5 != 0 && x % 3 != 0, x => x.ToString());
        rules.Add(x => true, x => "\n");
    
        var output = from n in Enumerable.Range(1, 100)
                     from f in rules
                     where f.Key(n)
                     select f.Value(n);
    
        output.ToList().ForEach(x => Console.Write(x));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello i am having trouble with passing a php return value to the innerHTML
I have two project and having trouble on passing value between two project. As
I am having trouble passing data read from a text file to another class
I'm having trouble getting any sense back from my mySQL database. I'm passing it
I am having trouble nailing down the best method for passing data from a
I'm having trouble passing view information from my Get/Create action to my view. Here
I'm having trouble passing an array between methods and have excerpted my code below.
I am having trouble passing data from one activity to another. I can easily
I'm having trouble with ASP.NET MVC and passing data from View to Controller. I
I am having a bit of trouble passing variable between forms. I have created

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.