Question
Convert to C# //Price Check.cpp //Uses a two-dimensional array to store a price list; //displays the price associated with a product ID #include #include #include
Convert to C#
//Price Check.cpp
//Uses a two-dimensional array to store a price list;
//displays the price associated with a product ID
#include
#include
#include
#include
using namespace std;
int main()
{ //declare variable and array
string searchForId = "";
string products[5][2] = {{"BX35", "13.00"},
{"CR20", "10.00"},
{"FE15", "12.00"},
{"KW10", "24.00"},
{"MM67", "4.00"}};
//get ID to search for, then convert to uppercase
cout << "Enter ID (X to exit): ";
getline(cin, searchForId);
transform(searchForId.begin(), searchForId.end(), searchForId.begin(), toupper);
while (searchForId != "X")
{
//locate position of product ID in the first column in the array
int row = 0; //keeps track of array subscripts
while (row < 5 && products[row][0] != searchForId)
{
row = row + 1;
}//end while
//if ID was found, display price from the second column in the array
//otherwise, display error message
if (row < 5)
{
cout << setiosflags(ios::fixed) << setprecision(2)
<< "Price for product ID " << products[row][0]
<< ": $" << products[row][1] << endl << endl;
}
else
{
cout << "Invalid product ID" << endl << endl;
}//end if
//get ID to search for, then convert to uppercase
cout << "Enter ID (X to exit): ";
getline(cin, searchForId);
transform(searchForId.begin(), searchForId.end(), searchForId.begin(), toupper);
}//end while
return 0;
}//end of main function
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started