Every time I type this up and use cin at the beginning to enter the company name all the numbers go crazy. Anyone have a clue why, I have spent hrs trying to find a typo or see if I mixed up something. I am at the point where I joined a forum for help.
#include <iostream>
#include <iomanip>
usingnamespace std;
int main()
{
/*LEGEND
lZ = 12
B = 8
cont = Container
bo = BackOrder
ihpc = Inch Hearts Per Container
lZ is twelve and B is eight
cont is container, bo is Backorder
*/
int lZhearts, Bhearts, lZcont, Bcont, lZbo, Bbo, company;
//Constants
constint lZihpc =20; //the 20 twelve inch hearts per container
constint Bihpc =32; //the 32 twelve inch hearts per container
constint lZic = 42.50; //for the cost of 12 inch containers
constint Bic =48.50; //for the cost of 8 inch containers
//Intro
cout << " Welcome to Name' s candy company " << endl;
cout << endl;
//Enter Company Name
cout << " Enter the name of the company placing the order:";
cin >> company;
cout << endl;
//Hearts Per Container
cout << " 20 twelve inch hearts per container.\n 32 eight inch hearts per container "<< endl;
cout << endl;
//Enter amount of 12 or 8 inch hearts
//lZ 12 inch heart user input
//Bhearts 8 inch heart user input
cout << " Enter the number of 12 inch hearts: ";
cin >> lZhearts;
cout << "\n Enter the number of 8 inch hearts: ";
cin >> Bhearts;
cout << endl;
//Output
//Order Summited By
cout << " This order was submitted by " << setw (20) <<company;
cout << endl;
//Number of 12 and 8 Inch Hearts
cout << " The number of 12 inch hearts = " << setw (20) <<lZhearts <<endl;
cout << " The number of 8 inch hearts = " << setw (20) <<Bhearts <<endl;
//captured output
cout << endl;
//Number of 12 Full Container
cout << " The number of full 12 inch containers = " << setw(20)<< lZhearts/lZihpc << endl;
//12 in Hearts on BackOrder
cout << " 12 inch hearts on backorder = " << setw (20) <<lZhearts % lZihpc <<endl;
//Number of Full 8 inch Containers
cout << " The number of full 8 inch containers = " << setw (20) <<Bhearts / Bihpc <<endl;
//8 in Hearts on BackOrder
cout << " 8 inch hearts on backorder = " << setw (20) <<Bhearts % Bihpc <<endl;
//The number of Hearts / By Hearts per Container
double lZcrt = lZhearts/lZihpc;
double Bcrt = Bhearts / Bihpc * Bic;
cout << " Cost of 12 inch hearts shipped = " << setw (20) <<lZcrt * lZic <<endl;
cout << " Cost of 8 inch hearts shipped = " << setw (20) <<Bcrt <<endl;
double total = lZcrt + Bcrt;
cout << endl;
cout << " Total cost = "<< setw(48) << Bcrt << endl;
system("PAUSE");
return 0;
}
Well, we have the problem then. You can't have text in an int type; its like putting a box in a triangular hole. You should probably use a string instead, which you can do by including <string> and using type string.
Thank You. now I just need 2 tweak it and fine tune some of the code 2 make it a lil more pretty. But i do have 1 more question. Whats the rule with decimals? ie I have 42.50 as a constant and I later multiply it, but my number comes up a little shy. Is there a golden rule with constants and ...? (if its a confusing question I am sorry)
Just a thing to remember, kiri, you should really use getline(cin, company) so that your program takes in the whole company name, and not just until the first white space. It'll just make the program less error prone and future proof if you expand it.