I'm having trouble with my homework in my intro to programming class.
"Mark Daniels is a carpenter who creates personalized house signs. He wants an application to compute the price of any sign a customer orders, based on the following factors:
The minimum charge for all signs is $30.
If the sign is made of oak, add $15. No charge is added for pine.
The first six letters or numbers are included in the minimum charge; there is a $3 charge for each additional character.
Black or white characters are included in the minimum charge; there is an additional $12 charge for gold-leaf lettering.
Design a program that accepts data for an order number, customer name, wood type, number of characters, and color of characters. Display all the entered data and the final price for the sign."
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
|
// HouseSign.cpp - This program calculates prices for custom made signs.
#include <iostream>
#include <string>
using namespace std;
int main()
{
// This is the work done in the housekeeping() function
// Declare and initialize variables here
int signCharge = 30;// Charge for this sign
string letterColor;// Color of characters in sign
int characterCount;// Number of characters in sign
string woodType;// Type of wood
string oak;
string gold;
int oakCharge = 15;
int colorCharge = 12;
int characterCharge = 3;
cout << "Input the character color. Black, white, or gold... ";
cin >> letterColor;
cout << "Input the number of characters that will appear on the sign. ";
cin >> characterCount;
cout << "Input the type of wood the sign will be made from. Oak or pine... ";
cin >> woodType;
// This is the work done in the detailLoop() function
// Write assignment and if statements here
if (letterColor == "gold")
signCharge += +(colorCharge);
else if (woodType == "oak")
signCharge += +(oakCharge);
else if (characterCount > 6)
signCharge += characterCharge * (characterCount - 6);
// This is the work done in the endOfJob() function
// Output charge for this sign
cout << "The charge for this sign is $" << signCharge << "." << endl;
cout << "The sign will be made of " << woodType << "," << endl;
cout << "and will contain " << characterCount << " characters with " << letterColor << " coloring." << endl;
system("pause");
return(0);
}
|
This is what I have set up so far.
The problem I'm having is that the program will only calculate the extra cost of one of my "if" conditions. For instance, if I run the program and input "gold" for the color, 5 characters, and "oak" wood; the output for the cost will be 42. The program only uses the first condition it finds true instead of each of them. If I input more than 6 for "characterCount" and oak wood; it will calculate the sign cost adding only the characterCost and not the oakCharge.
Can anybody tell me how to make each of the conditions be tested so that the cost is calculated properly?
Thanks!