Need help on simple program

For fun I am writing a little conversion program. I was wondering if it was possible to enter decimal number (i.e. 0.25) for the input?

Here is the issue i am getting:

I have a input of .25 meters and I want to convert it to cm.
This is the output I get:
1 meter is 25 centimeters
Mmhmm. You'd just need to use the float type instead of the int type for your variables. I presume.

...it'd help if you had some code to show us. :)

-Albatross
Last edited on
here is the code:
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
#include <iostream>
#include <iomanip>
#include <stdlib.h>

using namespace std;

//functions
int Menu();
int UserChoice();

//Global Menu Choices
const int Centimeter=1;

//End menu Choices

//Centi menu
const int Meter2=1;
const int In2=2;
const int Ft2=3;
//Global
int Choice; //Menu Choice
int choice2;
long double Pi=3.1415926535;
double MeterInput;
float InchInput;
double FeetInput;
double CentimeterOut;

//End global

int main()
{
	
int q;

	
Menu();
UserChoice();
	
	
cin>>q;
	
return 0;
}

int Menu()
{
	//The Menu
	cout<<"\t\tPlease Make a Choice:\n\n"
	    <<"1. Convert to Centimeters\n\n"
	    <<"Enter your choice: ";
	cin>>Choice;
//Clear the screen
system ("cls");


}
int UserChoice()
{
//cout<<setiosflags(ios::fixed)<<setprecision(2);
switch (Choice)
{
	case Centimeter:
	cout<<"\t\tPlease Make a Choice:\n\n"
		<<"1. Meters\n"
		<<"2. Inches\n"
		<<"3. Feet\n\n"
		<<"Enter your choice: ";
	cin>>choice2;
	cout<<endl;
	//Clear the screen
	system ("cls");
switch (choice2)
{	
	case Meter2:
		cout<<"Please enter a meter: ";
		cin>>MeterInput;
		cout<<endl;
		CentimeterOut=MeterInput*100; //calculation
		if (MeterInput=1)
		{
		cout<<MeterInput<<" meter is "<<CentimeterOut<<" centimeters"<<endl;
		}
		else if (CentimeterOut=1)
		{
		cout<<MeterInput<<" meters is "<<CentimeterOut<<" centimeter"<<endl;
		}
		else
		{
		cout<<MeterInput<<" meters is "<<CentimeterOut<<" centimeters"<<endl;
		}
	break;
	
	case In2:
		cout<<"Please enter a Inch: ";
		cin>>InchInput;
		cout<<endl;
		CentimeterOut=InchInput*2.54; //calculation
		if (InchInput=1)
		{
		cout<<InchInput<<" inche is "<<CentimeterOut<<" centimeters"<<endl;
		}
		else if (CentimeterOut=1)
		{
		cout<<InchInput<<" inches is "<<CentimeterOut<<" centimeter"<<endl;
		}
		else
		{
		cout<<InchInput<<" inches is "<<CentimeterOut<<" centimeters"<<endl;	
		}
		break;
}
}
}


Lines 80, 89, 99, and 103: You're using the assignment operator instead of the comparison operator. That might explain something. ;)

-Albatross
Topic archived. No new replies allowed.