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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:39:03+00:00 2026-06-03T09:39:03+00:00

I almost got my little console-app working, the only problem is that the variable

  • 0

I almost got my little console-app working, the only problem is that the variable totalComm keeps having the value 0.

I tried everything, I probably just overlooked a small fix which would solve the problem.

Thanks in advance

Philip

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

namespace CommissionCalculator
{
 class Program
  {
    public static void Main()
    {
        double total;
        double comm = 0;
        double totalComm = 0;
        string name = "";

        string inputLetter = "";
        int whilecount = 0;           

        while (inputLetter != "z")
        {
            if (whilecount == 0)
            {
                Title();
                whilecount = whilecount + 1;
            }

            getNameSales(out inputLetter, out name, out total, comm, totalComm);

            calcComm(total, out comm);

            outputVar(name, total, comm);

            totalCommCalc(comm, totalComm);
        }
    }

    public static void Title()
    {
        Console.WriteLine("\n           Sunshine Hot Tubs \n        Sales Commissions Report\n");
    }

    public static void getNameSales(out string inputLetter, out string name, out double total, double comm, double totalComm)
    {
        name = "";
        inputLetter = "";
        total = 0;

        Console.WriteLine("\nEnter salespersons initial a,b or e or enter z to quit");

        inputLetter = Console.ReadLine();

            if (inputLetter == "a")
            {
                name = "Andrea";

                string inValue;
                double sale = 0;
                total = 0;

                for (int count = 1; count <= 3; ++count)
                {
                    Console.WriteLine("Please enter sale: ");
                    inValue = Console.ReadLine();
                    sale = Convert.ToDouble(inValue);

                    total = total + sale;
                }
            }
            else if (inputLetter == "b")
            {
                name = "Brittany";

                string inValue;
                double sale = 0;
                total = 0;

                for (int count = 1; count <= 3; ++count)
                {
                    Console.WriteLine("Please enter sale: ");
                    inValue = Console.ReadLine();
                    sale = Convert.ToDouble(inValue);

                    total = total + sale;
                }
            }
            else if (inputLetter == "e")
            {
                name = "Eric";

                string inValue;
                double sale = 0;
                total = 0;

                for (int count = 1; count <= 3; ++count)
                {
                    Console.WriteLine("Please enter sale: ");
                    inValue = Console.ReadLine();
                    sale = Convert.ToDouble(inValue);

                    total = total + sale;
                }
            }
            else if (inputLetter == "z")
            {
                totalCommCalc(comm, totalComm);

                Console.WriteLine("Total commssion paid: {0:C}", totalComm);

                Console.ReadKey();
            }
        }

    public static void calcComm(double total, out double comm)
    {
        comm = total * 0.2;
    }

    public static double totalCommCalc(double comm, double totalComm)
    {            
        totalComm = totalComm + comm;

        return totalComm;
    }

    public static void outputVar(string name, double total, double comm)        
    { 
        Console.WriteLine("\n Name\t       Total sales\t     Commission \n{0}     \t    {1}     \t      {2}", name, total, comm);            
    }
  }
}
  • 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-03T09:39:05+00:00Added an answer on June 3, 2026 at 9:39 am

    totalComm is passed by value to totalCommCalc. Either pass it by reference, or return it from totalCommCalc and assign back to totalComm.

    When a variable is passed by value, a copy is placed on the stack of the method you call. Changes to that copy do not affect the original.

    When you pass by reference, the address of the original is placed on the stack, and changes do affect the original.

    Option 1:

    // Passed by reference.
    // Changes affect original.  
    // Has side effects.  See http://en.wikipedia.org/wiki/Side_effect_%28computer_science%29
    totalCommCalc(comm, ref totalComm);  
    

    Option 2:

    // Preferred.  Passed by value.  
    // Result is assigned to a variable.  
    // No side effects.
    totalComm = totalCommCalc(comm, totalComm); 
    

    I would prefer the second form, as code that has side effects can be harder to understand and maintain as it grows.

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

Sidebar

Related Questions

I've almost got it finished. but there's a little problem in adding comments. I've
I've almost got this working apart from one little annoying thing... Because the ListBox
we've got an almost-finished-ready-to-go magento shop, that has developed an annoying problem. On the
I'm dangerously close to launching a pretty heavy web app and I've got almost
I got a RSA pubkey.dat (almost obvious what it is) that has the following
I've got a weird issue that almost seems like a Visual Studio 2008 issue.
Almost every ios app now has something like Feed option. Programming that usually includes
I got a little problem, what I think, can't be hard. but somehow, I
I've got a big project written in PHP and Javascript. The problem is that
I've got a WPF application. Most of the time, the app uses almost no

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.