Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello everyone!
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.Write(item_one, " (" + itemone_quantity + " )");
        Console.Write(itemone_cost, " (" + itemone_total + " )");
        Console.WriteLine();
        Console.Write(itemtwo, " (" + itemtwo_quantity + " )");
        Console.Write(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 havent found anything that deeply explains everything. Sorry I am still learning and I am open to any advice or tips.

I receive an error for:
item_one = Console.ReadLine();
itemone_quantity = int.Parse(Console.ReadLine());
itemone_cost = float.Parse(Console.ReadLine());
Console.Write(item_one, " (" + itemone_quantity + " )");
Console.Write(itemone_cost, " (" + itemone_total + " )");
Console.Write(itemtwo, " (" + itemtwo_quantity + " )");
Console.Write(itemtwo_cost, " (" + itemtwo_total + " )");

Thank you
Posted
Updated 21-Jan-23 10:22am

1 solution

You just need to add this line:
C#
using System.IO;
That tells the system to look in the System.IO namespace as well as the System and Assignment1B namespaces.

Then to fix the others you probably want to use Console.WriteLine instead of Console.Write and look at using string interpolation[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900