I cant enter a decimal in a cin without the program jumping to the end.

When i run the program i answer the first question with a 0.5 and it just goes to the end of the program and i cant figure out why the program does not accept a decimal. Iv'e tried double float int long double and it all seems to do the same thing PLEASE 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
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
//Charles Diaz
//The purpose of this program is to calculate the deflection of a beam made by the user.

#include<iostream>
using namespace std;

int main()
{

float widthWeb;
float widthFlange;
float heightWeb;
float negativeSpace;
float length;
float density;
float psi;


//Receive users information on beam.

cout << "Enter the width of the web beam.\n";
cin >> widthWeb;

cout << "Enter the width of the flange beam.\n";
cin >> widthFlange;

cout << "Enter the height of the web beam.\n";	
cin >> heightWeb;

cout << "Enter the amount of negative space.\n";
cin >> negativeSpace;

cout << "Enter the lentgh of the beam.\n";
cin >> length;

//Formula and answer for cubic inches of beam.

float inches = ((widthWeb * widthFlange) + 2 * (heightWeb * negativeSpace)) * length;


cout << "This is the measurement of your beam in cubic inches." << endl;
cout << "Your beam measures" << inches <<"  Cubic inches.\n";

//  Converting cubic inches into cubic feet.

float feet = (inches *  0.00057870);

cout << "This is your cubic inches converted into cubic feet.\n";
cout << feet;

//Asking for more info from user to determine the mass of the beam.

cout << "Now we will find the mass of the beam. In order to do so you need the density of the wood you are using.\n";

cout << "Enter the density of your wood.\n";
cin >> density;

float mass = (feet * density);

cout << "The mass of your beam is:" << mass << endl;

//Convert mass from pounds to grams.

cout << "In order to calculate the beams deflection we must know the mass in grams instead of pounds and the inertia of the beam.\n";

float grams = (mass / 0.0022046);

cout << "Your beams mass in grams is: " << grams << endl;

//Formula and awnser for the inertia of the beam.

cout << "The beams inertia is calculated by the formula (base * height^3 / 12).\n";

float inertia = ((widthFlange * heightWeb) / 12);

cout << "The inertia of the beam is " << inertia << "^4.\n";

//Asking for more information from user to determine deflection.

cout << "To determine the deflection of the beam you need the modulus of elasticity of the type of wood used.\n";
        
cout << "Enter the psi of the type of wood used.(Easily found on the internet).\n";
cin >> psi;
 
//Determining the deflection of the beam formula and awnser.

cout << "The cocnetrated load for this project is 275 pounds.\n";

int load = 275;

float deflection = (load * length^3) / (48 * (psi * inertia));
 
cout << "The beams deflection is " << deflection << "inches.\n";

//Over view of all awnsers from previous entry.

cout << "Area of beam -        Inches           Feet \n ";
cout << "------------          ------           --------\n";
cout << "                  "<< inches        << feet << endl;

cout << "Mass                  Pounds           Grams\n";
cout << "----                  ------           -----\n";
cout << "                  "<< mass          << grams << endl;

cout << "Inertia\n";
cout << "-------\n";
cout <<  inertia << endl;

cout << "Deflection\n";
cout << "----------\n";
cout <<  deflection << endl;

return 0;
	
It worked just fine for me (I think). Your output looks a little off, though. You might want to try printf for some of those outputs to make it easier to format them to the shape you think you have.

Also, line 91 doesn't work like that. ^ is the bitwise XOR operator. Use pow instead.

Since I didn't have any issues, could you give me a little bit more information on what line you are experiencing issues on and and where it goes after that line?
Topic archived. No new replies allowed.