T
tomakated
How come it won't print out the lowest price item and subtract it from the
list<?.
and also what kind of code do I need for if the answer equals "N"<?.
Item 1 $ 2.25
Item 2 $ 2.25
Item 3 $ 2.25
Item 4 $ 1.25
Coupon Discount $( 0)
----------------------------
Total $ 8
$
#include <iostream>
#include <iomanip>
double findcheapest(double, double, double, double);
void printresults (double, double, double, double, double, double,
double);
void instructions();
double get_item_price();
int getresponse();
int main()
{
double item1, item2, item3, item4, lowest=0, total;
char response;
instructions();
item1 = get_item_price();
item2 = get_item_price();
item3 = get_item_price();
item4 = get_item_price();
total = item1 + item2 + item3 + item4;
cout << "Do you have a coupon for this purchase? \n" ;
response = getresponse() ;
if (response == 'y')
{ lowest = findcheapest(item1, item2, item3,
item4);
total = total - lowest;
}
printresults (response, item1, item2, item3, item4,
total, lowest);
}
void instructions()
{
// Lets see if this works<!!!
}
double get_item_price()
{
double i;
cout << "Enter the four item prices you want to buy.";
cout << ": ";
cin >> i;
while (i<0)
{
cout << "Please enter a positive number: ";
cin >> i;
}
return i;
}
int getresponse()
{ char response;
cout << "(y or n): \n";
cin >> response;
}
double findcheapest (double item1, double item2, double item3,
double item4)
{ double lowest;
if (((item1 <= item2) && (item1 <= item3) && (item1 <=
item4)))
lowest = item1;
else if (((item2 <= item1) && (item2 <= item3) && (item2
<= item4)))
lowest = item2;
else if (((item3 <= item1) && (item3 <= item2) && (item3 <=
item4)))
lowest = item3;
else if (((item4 <= item1) && (item4 <= item2) && (item4 <=
item3)))
lowest = item4;
}
void printresults(double response, double item1, double item2,
double item3, double item4, double total, double lowest)
{
cout << "Item 1 $" << setw(10) << item1 << endl;
cout << "Item 2 $" << setw(10) << item2 << endl;
cout << "Item 3 $" << setw(10) << item3 << endl;
cout << "Item 4 $" << setw(10) << item4 << endl;
cout << "Coupon Discount $(" << setw(9) <<
lowest<<")"<< endl;
cout << "----------------------------" << endl;
cout << "Total $" << setw(10) << total << endl;
}
list<?.
and also what kind of code do I need for if the answer equals "N"<?.
Item 1 $ 2.25
Item 2 $ 2.25
Item 3 $ 2.25
Item 4 $ 1.25
Coupon Discount $( 0)
----------------------------
Total $ 8
$
#include <iostream>
#include <iomanip>
double findcheapest(double, double, double, double);
void printresults (double, double, double, double, double, double,
double);
void instructions();
double get_item_price();
int getresponse();
int main()
{
double item1, item2, item3, item4, lowest=0, total;
char response;
instructions();
item1 = get_item_price();
item2 = get_item_price();
item3 = get_item_price();
item4 = get_item_price();
total = item1 + item2 + item3 + item4;
cout << "Do you have a coupon for this purchase? \n" ;
response = getresponse() ;
if (response == 'y')
{ lowest = findcheapest(item1, item2, item3,
item4);
total = total - lowest;
}
printresults (response, item1, item2, item3, item4,
total, lowest);
}
void instructions()
{
// Lets see if this works<!!!
}
double get_item_price()
{
double i;
cout << "Enter the four item prices you want to buy.";
cout << ": ";
cin >> i;
while (i<0)
{
cout << "Please enter a positive number: ";
cin >> i;
}
return i;
}
int getresponse()
{ char response;
cout << "(y or n): \n";
cin >> response;
}
double findcheapest (double item1, double item2, double item3,
double item4)
{ double lowest;
if (((item1 <= item2) && (item1 <= item3) && (item1 <=
item4)))
lowest = item1;
else if (((item2 <= item1) && (item2 <= item3) && (item2
<= item4)))
lowest = item2;
else if (((item3 <= item1) && (item3 <= item2) && (item3 <=
item4)))
lowest = item3;
else if (((item4 <= item1) && (item4 <= item2) && (item4 <=
item3)))
lowest = item4;
}
void printresults(double response, double item1, double item2,
double item3, double item4, double total, double lowest)
{
cout << "Item 1 $" << setw(10) << item1 << endl;
cout << "Item 2 $" << setw(10) << item2 << endl;
cout << "Item 3 $" << setw(10) << item3 << endl;
cout << "Item 4 $" << setw(10) << item4 << endl;
cout << "Coupon Discount $(" << setw(9) <<
lowest<<")"<< endl;
cout << "----------------------------" << endl;
cout << "Total $" << setw(10) << total << endl;
}