Question Summary of all numbers List<>

marjar94

New member
Joined
Feb 21, 2022
Messages
3
Programming Experience
Beginner
Hello, I am new here.
I am looking for help / hints.
I have code to write that counts articles. After entering the code starting with A, do not count the tax, for B it is 8%, for the other codes 23% of the tax (I already have it), but I have a problem summing up these amounts, and the application should ask for many codes (I also have it) to time until we enter "sum" and only then adds up the codes dividing into net and gross. I have already started writing List <>, but is this the right direction?
I will be grateful for the hint, and not solving the task for me.

c#:
using System;
using System.Collections.Generic;
using System.Linq;

namespace KasaTest
{
    class Kasa
    {
        public static void Main(string[] args)
        {
            while (true)
            {
                Console.WriteLine("Hej, podaj kod produktu");
                try
                {                  
                    string productcode = Console.ReadLine();
                    string code = productcode.Substring(0, 1);

                    if (code == "exit")
                    {
                        return;
                    }

                    double number = Convert.ToInt64(productcode.Substring(1));
                    var sumowanie = new List<double> { number };

                    //var list = new List<double>
                    //{
                    //    number,
                    //};

                    //Console.WriteLine(code);
                    //Console.WriteLine(number);
                    //Console.WriteLine(productcode);
                    //Console.WriteLine(list);

                    if (code == "a" || code == "A")
                    {
                        Console.WriteLine("do zapłaty " + number / 100 + ",00 zł");
                    
                        continue;                      
                    }

                    if (code == "b" || code == "B")
                    {                      
                        Console.WriteLine("do zapłaty " + (number * 0.0108) + " zł");
                  
                        continue;
                    }
                    //if (productcode == "suma")
                    //{
                    //    Console.WriteLine(list.Sum());
                    //    continue;
                    //}
                    else
                    {                      
                        Console.WriteLine("do zapłaty " + (number * 0.0123) + " zł");
                      
                        continue;
                    }                
                }
                catch (FormatException)
                {
                    Console.WriteLine("UWAGA! Podaj właściwy kod");

                    continue;
                }            
            }
        }
    }
}
 
Last edited by a moderator:

Latest posts

Back
Top Bottom