Im very new to C# and I am trying to complete my assignment but I came across some errors that I don't understand how to fix or even what they are implying.
using System;
public class Assignment1B
{
public static void Main(string[] args)
{
string item_one, itemtwo;
int itemone_quantity, itemtwo_quantity;
float itemone_cost, itemtwo_cost, itemone_total, itemtwo_total;
// Asking first item
Console.Write("What are you buying? ");
item_one = Console.ReadLine();
Console.Write("How many? ");
itemone_quantity = int.Parse(Console.ReadLine());
Console.Write("What do they cost? ");
itemone_cost = float.Parse(Console.ReadLine());
Console.WriteLine();
// Asking second item
Console.Write("What else are you buying? ");
itemtwo = Console.ReadLine();
Console.Write("How many? ");
itemtwo_quantity = int.Parse(Console.ReadLine());
Console.Write("What do they cost? ");
itemtwo_cost = float.Parse(Console.ReadLine());
Console.WriteLine();
// Math
itemone_total = itemone_quantity * (float)itemone_cost;
itemtwo_total = itemtwo_quantity * (float)itemtwo_cost;
// Listing everything
Console.WriteLine("Your list:");
Console.WriteLine("--------");
Console.WriteLine("{0} ({1})", item_one, itemone_quantity);
Console.WriteLine("{0} ({1})", itemone_cost, itemone_total);
Console.WriteLine();
Console.WriteLine("{0} ({1})", itemtwo, itemtwo_quantity);
Console.Write("{0} ({1})", itemtwo_cost, itemtwo_total);
}
}
The assignment wants me to asks you for the name, quantity, and price of two grocery store items. Then display them as a list.
What I have tried: I have tried looking up the error codes individually to try and see if I can find an example to get a better understanding of why I am getting the error but I haven't found anything that deeply explains everything. Sorry I am still learning and I am open to any advice or tips.
Errors that I have:
item_one = Console.ReadLine(); Warning CS8600: Converting null literal or possible null value to non-nullable type
itemone_quantity = int.Parse(Console.ReadLine()); Warning CS8604: Possible null reference argument for parameter 's' in 'int int.Parse(string s)'.
itemone_cost = float.Parse(Console.ReadLine()); Warning CS8604: Possible null reference argument for parameter 's' in 'float float.Parse(string s)'.
itemtwo = Console.ReadLine(); Warning CS8600: Converting null literal or possible null value to non-nullable type.
itemtwo_quantity = int.Parse(Console.ReadLine()); Warning CS8604: Possible null reference argument for parameter 's' in 'int int.Parse(string s)'.
itemtwo_cost = float.Parse(Console.ReadLine()); Warning CS8604: Possible null reference argument for parameter 's' in 'float float.Parse(string s)'.