Question

In: Computer Science

C# - count =0; - Create a 2d array "items". string[,] items = new string[100, 4];...

C#

- count =0;
- Create a 2d array "items".
string[,] items = new string[100, 4];


- Create a do while loop, when the user enters "0", stop the loop.
- Users enter the item name, price, quantity, save this info and subtotal to array.
- increase "count++"

-convert price(decimal, Convert.ToDecimal() ) and quantity(int) to do multiplication
for subtotal

- create a for loop (with count ) to cycle through the "items", display item name, price, quantity,
and subtotal.
accumulate subtotal

- Display total items, subtotal, total at the end.

Guide:

string[,] items = new string[100, 4];
int i, j, count;

/* input each array element's value */
for (i = 0; i < 100; i++) {

items[i,0] = Console.ReadLine("Enter Item Name: ");

if items[i,0] == "0"
break;
else
count++;

items[i,1] = Console.ReadLine("Enter Item Price: ");
items[i,2] = Console.ReadLine("Enter Item Quantity: ");
items[i,3] = (Convert.ToDouble(items[i,1])*Convert.ToDouble(items[i,2])).toString();

}

/* output each array element's value */
for (i = 0; i < count; i++)
{
for (j = 0; j < 4; j++) {
Console.WriteLine(items[i,j], " ");
}
}

Solutions

Expert Solution

Dear Student ,

As per requirement submitted above kindly find below solution.

Here new console application in C# is created using visual studio 2019 with name "_2DArray". This application contains a class with name "Program.cs".Below is the details of this class.

Program.cs :

//namespace
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//application namespace
namespace _2DArray
{
class Program //C# program
{
//main() method
static void Main(string[] args)
{
//Create a 2d array "items".
string[,] items = new string[100, 4];
//declaring variables
int i = 0, count = 0;
double subtotal = 0;
//do while loop,
do
{
//asking user item name
Console.Write("Enter Item Name: ");
//reading item name
String itemName = Console.ReadLine();
//checking item name
if (itemName == "0")
//if item name is 0 then break the loop
break;
else
//increment count
count++;
items[i, 0] = itemName;
//asking item price
Console.Write("Enter Item Price: ");
items[i, 1] = Console.ReadLine();//reading item price
//asking item quantity
Console.Write("Enter Item Quantity: ");
items[i, 2] = Console.ReadLine();//reading quantity

items[i, 3] = (Convert.ToDouble(items[i, 1]) * Convert.ToDouble(items[i, 2])).ToString();
subtotal = subtotal + Convert.ToDouble(items[i, 1]) * Convert.ToDouble(items[i, 2]);
i++;
} while (i < 100);
//using for loop display details
/* output each array element's value */
for (i = 0; i < count; i++)
{
//display details
Console.WriteLine("Item Name :" + items[i, 0]);
Console.WriteLine("Item Price :" + items[i, 1]);
Console.WriteLine("Item Quantity :" + items[i, 2]);
Console.WriteLine("subtotal :" + items[i, 3]);
}
//display subtotal
Console.WriteLine("Total : " + subtotal);

}
}
}

==================================

Output :Run application using F5 and will get the screen as shown below

NOTE :PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.


Related Solutions

In C, build a connect 4 game with no GUI. Use a 2D array as the...
In C, build a connect 4 game with no GUI. Use a 2D array as the Data structure. First, build the skeleton of the game. Then, build the game. Some guidelines include... SKELETON: Connect Four is a game that alternates player 1 and player 2. You should keep track of whose turn it is next. Create functions: Initialization – print “Setting up the game”. Ask each player their name. Teardown – print “Destroying the game” Accept Input – accept a...
Java- Create a new class named Forest that has a 2D array of integers to store...
Java- Create a new class named Forest that has a 2D array of integers to store a forest. Create a private inner class Position to store the row and column of the current cell. Create a Depth First Search Method that uses a stack to remove the current tree and search its neighbors based on the following pseudocode: // given a forest "f" // store positions on fire Stack<Position> cellsToExplore // the forest is aflame! for each tree in the...
In C create an array of 4 integers. Assign a pointer to the array. Use the...
In C create an array of 4 integers. Assign a pointer to the array. Use the pointer to find the average value of the elements in the array and display the results on the screen.
Submit a well-commented C program.   Create code. That will build a random 8x8 2D array of...
Submit a well-commented C program.   Create code. That will build a random 8x8 2D array of small-case characters. Demonstrate how it functions by printing out the result on your screen. Add a function will print out a single line of the array. If the user enters a value between 0 and 7 to select to print out a single row of the original 2D array.                void printLine(char *,int);    // This is the prototype declaration             void printLine(char myArr[][])     //...
When you create a C string (an array of chars) without the * symbol for pointer,...
When you create a C string (an array of chars) without the * symbol for pointer, is the pointer towards the 1st char created or not along with the array?
in C programming language char character [100] = "hello"; a string array variable It is given....
in C programming language char character [100] = "hello"; a string array variable It is given. By writing a function called TranslateString, By accessing the pointer address of this given string, returning the string's address (pointer address) by reversing the string Write the function and use it on the main function. Function void will not be written as. Return value pointer address it will be. Sweat operation on the same variable (character) It will be made. Declaration of the function...
Write a recursive method to determine if a String is a palindrome. Create a String array...
Write a recursive method to determine if a String is a palindrome. Create a String array with several test cases and test your method. Write a recursive method to determine if a String is a palindrome. Create a String array with several test cases and test your method. In Java
Write a C program that generates the following 2D array. 64   32   16   8   4   2  ...
Write a C program that generates the following 2D array. 64   32   16   8   4   2   1 32   32   16   8   4   1   1 16   16   16   8   4   2   1 8   8   8   8   4   2   1 4   4   4   4   4   2   1 2   2   2   2   2   2   1 1   1   1   1   1   1   1
Develop a python program to - Create a 2D 10x10 numpy array and fill it with...
Develop a python program to - Create a 2D 10x10 numpy array and fill it with the random numbers between 1 and 9 (including 0 and 9). - Assume that you are located at (0,0) (upper-left corner) and want to move to (9,9) (lower-right corner) step by step. In each step, you can only move right or down in the array. - Develop a function to simulate random movement from (0,0) to (9,9) and return sum of all cell values...
Instructions (No array) (c++) (visual studio) 1. Create a project called Project3B 2. Create 3 String...
Instructions (No array) (c++) (visual studio) 1. Create a project called Project3B 2. Create 3 String variables called name1, name2, name3 3. Create 9 double variables called test1_1, test1_2, test1_3, test2_1, test2_2, test2_3, test3_1, test3_2, test3_3 4. Create 3 double variables called average1, average2, average3 To calculate the average score = (test1 + test2 + test3) / 3.0 5. Run the program with the following data using cin name1 = “Tom”, name2 = “Mary”, name3 = “Ali” test1_1 = 81.4,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT