error because of cin?

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.
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
#include <iostream>
#include <iomanip>
using namespace 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
const int lZihpc =20;     //the 20 twelve inch hearts per container
const int  Bihpc =32;     //the 32 twelve inch hearts per container
const int  lZic = 42.50; //for the cost of 12 inch containers 
const int 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;
}
Are you trying to enter a string into an int? Are you entering text or numbers when prompted for company?
1
2
cout << "  Enter the name of the company placing the order:"; 
cin >> company; 


Input is text and it is making everything else not working
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.
Company should be a string..
You probably might want to make company a getline since you might be getting the name of the whole company
First do this
 
String company;

Then,
1
2
3
cout << "Enter the name of the company placing the order: ";  << endl;

    getline (cin, company)

Should work fine.
--Justin
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)
Blackhart I added #include <string>

string company; cin >> company;
and have had no issues yet.
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.
geniusberry, thanks I am going 2 look into it and try to learn more about that too.
Topic archived. No new replies allowed.