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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:36:24+00:00 2026-06-14T08:36:24+00:00

I’ve received two files: Sumator.cs and Kalkulator.cs @ Visual Studio 2012 I think you

  • 0

I’ve received two files: Sumator.cs and Kalkulator.cs @ Visual Studio 2012

I think you don’t need to see those two, but I did put them here anyways, go down page and check my problem.

Sumator.cs code:

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

namespace Sumator2
{
class Sumator
{
    bool Status = false;
    double Suma = 0;
    public Kalkulator Kalk = new Kalkulator();
    public Sumator()
    {
    }

    public void ZmienStatus()
    {
        Status = !Status;
    }
    public string PokazStatus()
    {

        if (Status == true)
            return " Sumator włączony";
        else
            return " Sumator wyłaczony";

    }

    public void PokazWynikS()
    {
        if (Status == true)
            Suma += Kalk.Wynik;
        Console.WriteLine("Wynik działania : " + Kalk.L1.ToString() + " " + Kalk.Dzialanie.ToString() + " " + Kalk.L2.ToString() + " = " + Kalk.Wynik.ToString() + PokazStatus() + "   Suma= " + Suma.ToString());
    }

    public void Zeruj()
    {
        Suma = 0;
    }
}
}

Kalkulator.cs code:

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

namespace Sumator2
{
class Kalkulator
{
    public double L1;
    public double L2;
    public double Wynik;
    public String Dzialanie = "";
    public Kalkulator()
    {
    }
      void Oblicz()
    {
        switch (Dzialanie)
        {
            case "+":
                Wynik = L1 + L2;
                break;
            case "-":
                Wynik = L1 - L2;
                break;
            case "*":
                Wynik = L1 * L2;
                break;
            case "/":
                Wynik = L1 / L2;
                break;

        }
    }
    public void PodajDzialanie(double licz1, double licz2, string dz)
    {
        L1 = licz1;
        L2 = licz2;
        Dzialanie = dz;
        Oblicz();

    }
    public void PokazWynik()
    {
        Console.WriteLine("Wynik działania : " + L1.ToString() + " " + Dzialanie.ToString() + " " + L2.ToString() + " = " + Wynik.ToString());
    }

}
}

and I’ve written my main code for those two.
Program.cs code:

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

namespace Sumator2
{
class Program
{
    static void Main(string[] args)
    {
        Sumator s1 = new Sumator();

        s1.ZmienStatus();

        bool userNum = true;
        while (userNum)
        {
            double userDouble;
            string userString = Console.ReadLine();

            if (userNum = double.TryParse(userString, out userDouble))
            {
                userDouble = Convert.ToDouble(userString);
                userNum = false;
            }
            else 
            {
                Console.WriteLine("Nie podano liczby!");
                userNum = true;
            }
        }


        s1.Kalk.PodajDzialanie(userDouble, 2, "*");
        s1.PokazWynikS();
        s1.Kalk.PokazWynik();

        s1.Kalk.PodajDzialanie(userDouble, 2, "+");
        s1.PokazWynikS();
        s1.Kalk.PokazWynik();


        Console.ReadKey();
    }
}
}

Problem is that I wanted to use s1.Kalk.PodajDzialanie() function with those arguments:

 s1.Kalk.PodajDzialanie(userDouble, 2, "*");

and I got error like:

 The name 'userDouble' does not exists in the current context

I mean wt*? This function does work normally if I do like:

 s1.Kalk.PodajDzialanie(2, 2, "*");
  • 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-14T08:36:25+00:00Added an answer on June 14, 2026 at 8:36 am

    You’re declaring userDouble inside your while loop. Once you leave that loop, it’s out of scope. Move it to before the loop and you should be fine. So instead you have:

    bool userNum = true;
    double userDouble;
    while (userNum)
    {      
        string userString = Console.ReadLine();
    
        // Jesli sa liczby to convertujemy
        if (userNum = double.TryParse(userString, out userDouble))
        {
            userDouble = Convert.ToDouble(userString);
            userNum = false;
        }
        else 
        {
            Console.WriteLine("Nie podano liczby!");
            userNum = true;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
I need to clean up various Word 'smart' characters in user input, including but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I've tracked down a weird MySQL problem to the two different ways I was

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.