I am working on an Assignment that asks me to do this:
Develop a C# console application that implements two parallel arrays in Main, one to hold double values called item_price and the other to hold strings called item_name. Each array will hold 5 values. Use an initializer to fill the item_price array with the values 15.50, 50.99, 25.00, 115.49, 75.25. Use an initializer to fill the item_name array with the values "Widget", "Thingy", "Ratchet", "Clanger", "Fracker". This application will use a method to change the corresponding prices for items based on a price point and a multiplier which will require double value types. The inputs for the price and multiplier are input from the console.
Create two static methods, one called changePrices and one called printit. When the changePrices method is called from Main you should pass the item_price array by reference, the price point and price difference values input from the console to it. The changePrices method should loop through the item price array and check the price point to determine the increase in price for each price array element. The basic computation is:
if the current price is less than the price point then set the price equal to the current price plus the current price times the price multiplier
In the printit method print the item name and the corresponding item price to the console as shown in the output example below.
The price for item Widgetis $15.50 The price for item Thingyis $50.99 The price for item Ratchetis $25.00 The price for item Clangeris $115.49 The price for item Frackeris $75.25
Enter the price cutoff point (eg $15.00) $60.00 Enter the percentage price change (eg 0.25)0.15
The price for item Widgetis $17.83 The price for item Thingyis $58.64 The price for item Ratchetis $28.75 The price for item Clangeris $115.49 The price for item Frackeris $75.25
Press any key to continue...
As shown in the sample output, your program will first use the printit method to print the parallel arrays as they are, next take inputs for the price point and the price change multiplier and then after the changePrices method has been executed run the printit method once again to show any changed prices.
I keep getting an error stating, "Cannot implicitly convert type 'double' to 'int'. An explicit conversion exist (are you missing a cast?) on
Line 32 Console.WriteLine("The price for item " + (item_name[x]) + "is " + item_price[x]);
as well as several more errors. How can I fix this?
Here is my code:
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespaceAssignment_9{classProgram{double ppoint =0;double multi =0;staticvoidMain(string[] args){//two arraysdouble[] item_price ={15.50,50.99,25.00,115.49,75.25};string[] item_name ={"Widget","Thingy","Ratchet","Clanger","Fracker"};Console.WriteLine();
printit(item_name, item_price);Console.WriteLine();
changePrices(item_price);Console.WriteLine();
printit(item_name, item_price);}staticvoid printit(string[] item_name,double[] item_price){for(double x =0; x < item_price.Length; x++){Console.WriteLine("The price for item "+(item_name[x])+"is "+ item_price[x]);}}staticvoid changePrices(double[] passed){Console.WriteLine("Enter the price cutoff point (eg $15.00) $");
ppoint =Convert.ToDouble(Console.ReadLine());Console.WriteLine("Enter the percentage price change (eg 0.25)");
multi =Convert.ToDouble(Console.ReadLine());for(double x =0; x < item_price.Length; x++){if(x < ppoint){Console.WriteLine(x =(x +(x * multi)));}}}}}
Awesome! PowerToys just keeps rapidly getting better and better. 👏🏽 Looking forward to the day Peek matches the speed and compatibility of the QuickLook app on the Microsoft Store, and PowerRename matches the versatility of File Renamer Turbo.
maybe he is a Gypsie. There’s a guy I watch on YouTube (indigotraveller) and he just did a little series on the Romani Gypsies and gold is one of the most valued assets and like the super rich ones have everything made with gold just because.
I'm surprised they aren't using the horizontal space in addition to the vertical space and laying it out in an icon grid grouped by utility. By far most monitors have more horizontal space than vertical, too.
I count 22 items in that list (some more outside it). So let's say 30 modules in a long winded list. That's honestly just a 6x5 grid.
Question
thehappygoldenlady
I am working on an Assignment that asks me to do this:
Develop a C# console application that implements two parallel arrays in Main, one to hold double values called item_price and the other to hold strings called item_name. Each array will hold 5 values. Use an initializer to fill the item_price array with the values 15.50, 50.99, 25.00, 115.49, 75.25. Use an initializer to fill the item_name array with the values "Widget", "Thingy", "Ratchet", "Clanger", "Fracker". This application will use a method to change the corresponding prices for items based on a price point and a multiplier which will require double value types. The inputs for the price and multiplier are input from the console.
Create two static methods, one called changePrices and one called printit. When the changePrices method is called from Main you should pass the item_price array by reference, the price point and price difference values input from the console to it. The changePrices method should loop through the item price array and check the price point to determine the increase in price for each price array element. The basic computation is:
if the current price is less than the price point then set the price equal to the current price plus the current price times the price multiplier
In the printit method print the item name and the corresponding item price to the console as shown in the output example below.
The price for item Widget is $15.50
The price for item Thingy is $50.99
The price for item Ratchet is $25.00
The price for item Clanger is $115.49
The price for item Fracker is $75.25
Enter the price cutoff point (eg $15.00) $60.00
Enter the percentage price change (eg 0.25) 0.15
The price for item Widget is $17.83
The price for item Thingy is $58.64
The price for item Ratchet is $28.75
The price for item Clanger is $115.49
The price for item Fracker is $75.25
Press any key to continue . . .
As shown in the sample output, your program will first use the printit method to print the parallel arrays as they are, next take inputs for the price point and the price change multiplier and then after the changePrices method has been executed run the printit method once again to show any changed prices.
I keep getting an error stating, "Cannot implicitly convert type 'double' to 'int'. An explicit conversion exist (are you missing a cast?) on
Line 32 Console.WriteLine("The price for item " + (item_name[x]) + "is " + item_price[x]);
as well as several more errors. How can I fix this?
Here is my code:
Link to comment
https://www.neowin.net/forum/topic/1256148-c-parallel-arrays-passing-array-by-reference/Share on other sites
19 answers to this question
Recommended Posts