Hello this is my first post on this forum :). Can anyone please help me with my code? There seems to be a problem in both the Calculation of my data and my switch function.
Here are the instructions:
Write a program that computes the amount of money it costs to clean a carpet. The program needs to enter the following
information: Size of carpet --- The length and width of the total amount of carpet in feet (assume it is a rectangular shaped carpet).
Allow the user to enter the number of rooms and then for each room the length and width of the carpet in feet (assume every room has a rectangular shaped carpet).
[1] for normal carpets $5 per square yard
[2] for extra dirty carpets $6 per square yard
[3] for deodorizing your carpet $1.5 extra per square yard
[4] for carpets cleaned on Monday through Thursday no extra charge, for carpets cleaned on
Friday an extra $10 fee will be charged, for carpets cleaned on Saturday an extra $15 fee will
be charged, for carpets cleaned on Sunday an extra $20 fee will be charged,
The code below is what I have so far and I need the output and follow the rules here:
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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
#include <iostream.h>
#include "iomanip.h"
#include "apstring.h"
int length, width, day, priceperfoot, area;
char deodorize, extradirty;
double total;
void EnterData();
void CalculateCost();
void DisplayData();
void main()
{
EnterData();
CalculateCost();
DisplayData();
}
void EnterData()
{
cout<<"Please enter the length of the carpet in feet -->";
cin>>length;
while (length<=0)
{
cout<<"Incorrect length. Length must be positive, enter positive value -->";
cin>>length;
}
cout<<"Please enter the width of the carpet in feet -->";
cin>>width;
while (width<=0)
{
cout<<"Incorrect width. Width must be positive, enter positive value -->";
cin>>width;
}
do
{
cout<<"Would you like to deodorize the carpet? [Y,N]-->";
cin>>deodorize;
}
while (deodorize!= 'Y' && deodorize !='N'&& deodorize !='y'&& deodorize !='n');
cout<<"Is the carpet extra dirty?[Y,N]-->";
cin>>extradirty;
while ((extradirty != 'Y') && (extradirty != 'N') && (extradirty != 'y') && (extradirty != 'n'))
{
cout<<"Incorrect Input. Is the carpet extra dirty?[Y,N]-->";
cin>>extradirty;
}
do
{
cout<<"What day would you like your carpet cleaned?"<<endl<<endl;
cout<<"(1 -Monday, 2 -Tuesday, 3 -Wednesday, 4 -Thursday, 5 -Friday, 6 -Saturday, 7 -Sunday ) -->";
cin>>day;
cout<< endl <<endl;
switch(day)
{
case 1: cout<< "Monday";
break;
case 2: cout<<"Tuesday";
break;
case 3: cout<<"Wednesday";
break;
case 4: cout<<"Thursday";
break;
case 5: cout<<"Friday";
break;
case 6: cout<<"Saturday";
break;
case 7: cout<<"Sunday";
break;
default: cout<<"Enter a valid number [1-7]"<<endl;
}
}
while ((day != 1) && (day != 2) && (day != 3) && (day != 4) && (day != 5) && (day != 6) && (day != 7));
}
void CalculateCost()
{
area = length*width;
if (extradirty == 'Y' || extradirty =='y')
priceperfoot = 6;
else
priceperfoot = 5;
if (deodorize == 'Y' || deodorize =='y')
priceperfoot += 1.5;
total = priceperfoot * area;
if (day<5 && day>0)
total += 0;
else if (day == 5)
total += 10;
else if (day == 6)
total += 15;
else if (day == 7 )
total += 20;
}
void DisplayData()
{
cout<< endl << endl;
cout<< " Your cost for carpet cleaning will be ===> " << priceperyard * area<< endl;
cout<< " Day to be cleaned will be ===> " << day << endl;
}
|