Hi, I am new to C++ and I have a project due on friday. This is out first week with structures and I am struggling. I am trying to be able to pick a plant, get a count on how many of this plant and then calculate a price....each thing having a seperate function. Can someone help me out with what I am doing wrong on the third function?
#include
using namespace std;
struct plant
{
int choice;
float price;
float quantity;
};
plant pick(plant tulip);
//Pre: none
//Post: user has been informed of choices and passed on valid choice
//plant cost(plant tulip);
//Pre: need choice to be made and valid, and number of plants
//Post: cost of plant wanted * number desired
plant amount(plant tulip);
plant cost( int choice, int quantity, plant tulip);
Question
aitf311
Hi, I am new to C++ and I have a project due on friday. This is out first week with structures and I am struggling. I am trying to be able to pick a plant, get a count on how many of this plant and then calculate a price....each thing having a seperate function. Can someone help me out with what I am doing wrong on the third function?
#include
using namespace std;
struct plant
{
int choice;
float price;
float quantity;
};
plant pick(plant tulip);
//Pre: none
//Post: user has been informed of choices and passed on valid choice
//plant cost(plant tulip);
//Pre: need choice to be made and valid, and number of plants
//Post: cost of plant wanted * number desired
plant amount(plant tulip);
plant cost( int choice, int quantity, plant tulip);
int main()
{
plant plantChoice, plantQuantity, plantCost;
int totalCounter, counter;
plantChoice.choice = 1;
plantChoice.price = 1;
plantChoice.quantity = 1;
//plantChoice = pick(plantChoice);
//plantQuantity = amount(plantQuantity);
plantCost = cost( plantChoice, plantQuantity, plantCost);
return 0;
}
plant pick(plant tulip)
{
int counter;
cout << "Follow the onscreen instructions and press 0 to quitn"; //directions
cout << "The following plants are available: nn";
cout << "Plant#tPricen1t4.95n2t2.95n3t14.95n4t12.95n5t7.95n" << endl; //plant info
cout << "Please enter the plant# you would like (0 to quit): ";
cin >> tulip.choice;
while ((tulip.choice >5) || (tulip.choice <0)) // makes sure the plant# entered is valid
{
cout << "Enter a valid plant#.n";
cin >> tulip.choice;
}
switch (tulip.choice) //sets the price of the plant
{
case 0:
break;
case 1:
tulip.price=(float)4.95;
break;
case 2:
tulip.price=(float)2.95;
break;
case 3:
tulip.price=(float)14.95;
break;
case 4:
tulip.price=(float)12.95;
break;
case 5:
tulip.price=(float)7.95;
break;
default:
cout << "You did not enter a correct plant#." << endl;
}
return tulip;
}
plant amount(plant tulip)
{
cout << "How many sold: ";
cin >> tulip.quantity;
if (tulip.quantity < 0) //makes sure the number entered is positive
{ cout << "nPlease enter a positive number this time..." << endl;
cout << "How many sold: ";
cin >> tulip.quantity;
}
return tulip;
}
plant cost( int choice, int quantity, plant tulip)
{
choice = pick(tulip)
quantity = amount(tulip)
float price;
switch (choice) //sets the price of the plant
{
case 0:
break;
case 1:
price=(float)4.95;
break;
case 2:
price=(float)2.95;
break;
case 3:
price=(float)14.95;
break;
case 4:
price=(float)12.95;
break;
case 5:
price=(float)7.95;
break;
default:
cout << "Something went wrong!" << endl;
}
return tulip;
}
Link to comment
Share on other sites
2 answers to this question
Recommended Posts