Hi! I need some help on my assignment. My main problem right now is I cant get my function getPrice() to work. My assignment says I need to use an array i my struct, and I don't know what it wants me to do with the arrays? Lastly, I'm not sure how to get the total cost. I started to create a function to calculate the total, but I don't know what to write, and I can't really try anything since my first function isn't working. Thanks for your help in advance!!
Assignment: You have already done a catalog assignment. For reference, it is reproduced here:
An online catalogue sells five different products with the following single-unit prices:
prod 1 -$3.08
prod 2 - $4.52
prod 3 - $10.87
prod 4 - $4.49
prod 5 - $9.68
Write a program to read in pairs of numbers, with the first number being the product number and the second number being the quantity ordered. Your program should use a switch statement to look up the retail price, and then keep a running total of products ordered. Use a sentinel-controlled loop to ask the user for further orders until the user wants to stop. At that point, output the order information (number of each product ordered and total price).
You are to redo the catalog assignment. This time, product information is in a struct, containing members for the product number and the price. Your structs should be in an array. In your input loop, add a list of product numbers and prices so that the user can see what is on offer. Hmm.. do we want to specify volume discounts? I suppose not.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
#include <iostream>
#include <string>
using namespace std;
struct catalogue
{
int getPrice();
int totalCost ();
catalogue();
};
int getPrice (int num)
{
double price = 0;
switch (num)
{
case 1:
price = 3.08;
case 2:
price = 4.52;
case 3:
price = 10.87;
case 4:
price = 4.49;
case 5:
price = 9.68;
default:
price = 0;
}
return price;
}
int main ()
{
int prodNum;
catalogue mycat;
bool Repeat = true;
char YoN;
while (Repeat)
{
cout << "Please select a product:" << endl << endl;
cout << "Product 1 - $3.08\n\nProduct 2 - $4.52\n\nProduct 3 - $10.87\n\n"
<< "Product 4 - $4.49\n\nProduct 5 - $9.68" << endl;
cin >> prodNum;
if ((prodNum <= 0) || (prodNum >= 6))
{
cout << "You entered an invalid number.";
}
cout << endl;
mycat.getPrice(prodNum);
cout << "Would you like to enter another product? (Enter Y to continue): ";
cin >> YoN;
if (YoN == 'Y' || YoN == 'y')
{
Repeat = true;
}
else
return false;
cout << endl;
}
}
int totalCost(int num)
{
}
|