I am posting this here because it was suggested that it is the best place by a seasoned user.
This is a project I already submitted, but I never received feedback. All my upcoming assignments will be based on this, so I wanted to make sure it is correct. I got this program to work as far as calculating the information, but I was hoping someone could please let me know if it meets the parameters/requirements?
I did attempt it. It works and adds the items exactly how the example showed in the video. However, I wanted to make sure my code is solid, and not just a mishmash or working because I got lucky, and if there is a better more solid way to do this I want to make sure I can. I do want feedback so I can learn and get better and I am trying my hardest. I always right out all the code I see here and try it and learn what it does piece by piece, because it helps me learn and improve. I also want to make sure it is going to work once I start the code for the next half of the requirements.
**Write a Console program, let users to enter prices calculate subtotal, tax, and total. - Delcare variable data type as decimal (6 variables needed) decimal apple;
Conver string to decimal from input apple = Convert.ToDecimal(Console.ReadLine()); Do addition for subtotal Multiplication for tax (0.065M) --- M or m stands for money value, read page 94. Addition for total You need to show only two digits after decimal point The class example:
`Console.WriteLine(" Subtotal: ${0}", String.Format("{0:0.00}", subTotal)); blank line: Console.WriteLine("") Console.Write(" Apple: $"); apple = Convert.ToDecimal(Console.ReadLine());`
My code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CalculatorRun
{
class Calculator
{
static void Main(string[] args)
{
decimal FirstOperand, SecondOperand, Result, result;
Console.Write("Addition Calculation");
Console.Write(" \n\n");
Console.Write(" Enter first operand: ");
FirstOperand = Convert.ToDecimal(Console.ReadLine());
Console.Write(" Enter second operand: ");
SecondOperand = Convert.ToDecimal(Console.ReadLine());
Console.Write("-------------------------\n\n");
Result = FirstOperand + SecondOperand;
result = Convert.ToDecimal(Result);
Console.WriteLine("Addition Result: {0}", string.Format("{0}", result));
Console.WriteLine("Press any key to continue.....");
Console.ReadLine();
}
}
}
The next part of the assignment is this, which is what I need to make sure my code is correct so I can build towards:
Delcare variable data type as decimal (5 variables needed) count, price, subtotal, tax, total
Write a do while loop, if the price is not -1, loop continues show count number enter price get subtotal increase count
Calculate tax, total
Display total count, subtotal, tax, total
Feedback I received I am working on: What happens if the user enters an invalid number for either operand? (Thanks yo PaulF. I am not quit sure what this means, I think it means if someone enters a number such as -1. However, I will have to research a fix as this is a bit outside my realm).
This line is uncessary: result = Convert.ToDecimal(Result); because Result is already a decimal. You don't need two of them... (Thanks to Rufus L. I have to look into this and understand decimals more.)
This is the book I am using, and what I have to match so if some code seems oddly specific or old, that is why. https://cscnt.savannahstate.edu/StudentFiles/Data_Structure/Visual%20C%23%202012%20How%20to%20Program.pdf