C++ Error

#include<iostream>
#include<stdlib.h>//for exit
using namespace std;
void inchtocent(float);//prototypes for conversion function
void centtoinch(float);

int main()
{
float input;//input s float
int ch;
while(true) //repeat until the user wants to exit
{
cout<<"1.inch to centimeters\n2.centimeters to inches\n3.exit\nenter your option:";
cout<<endl;
cin>>ch;
switch(ch)
{
case 1:
cout<<"\nenter inches:"; //asking for input in inches
cin>>input;
inchtocent(input); //calling converion function
break;
case 2:
cout<<"\nenter centimetres:"; //asking for input in inches
cin>>input;
centtoinch(input);//calling converion function
break;
case 3:
exit(0);
default:
cout<<"wrong choice"; break;
}
}
return 0;
}

void inchtocent(float x)
{
float cent=x*2.54; //1cm=2.54 inch so multipling is conversion
cout<<"\n"<<x<<" inches = "<<cent<<" centimetres."<<endl;//printing the reulsts
}
void centtoinch(float x)
{
float inch=x*0.393701;//1 inch= 0.393701 cm so multipling with that is conversion
cout<<"\n"<<x<<" centimeters = "<<inch<<" inches."<<endl;//printing the reulsts
}




1>------ Build started: Project: ConsoleApplication1, Configuration: Debug Win32 ------
1> Source.cpp
1>c:\cpp8\chap 10\consoleapplication1\consoleapplication1\source.cpp(39): warning C4244: 'initializing' : conversion from 'double' to 'float', possible loss of data
1>c:\cpp8\chap 10\consoleapplication1\consoleapplication1\source.cpp(44): warning C4244: 'initializing' : conversion from 'double' to 'float', possible loss of data
1> ConsoleApplication1.vcxproj -> C:\Cpp8\Chap 10\ConsoleApplication1\Debug\ConsoleApplication1.exe
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========



Can someone help me with this error

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
#include<iostream>
#include<stdlib.h>//for exit
using namespace std;
void inchtocent(float);//prototypes for conversion function
void centtoinch(float);

int main()
{
float input;//input s float
int ch;
while(true) //repeat until the user wants to exit
{
cout<<"1.inch to centimeters\n2.centimeters to inches\n3.exit\nenter your option:";
cout<<endl;
cin>>ch;
switch(ch)
{
case 1:
cout<<"\nenter inches:"; //asking for input in inches
cin>>input;
inchtocent(input); //calling converion function
break;
case 2:
cout<<"\nenter centimetres:"; //asking for input in inches
cin>>input;
centtoinch(input);//calling converion function
break;
case 3:
exit(0);
default:
cout<<"wrong choice"; break;
}
}
return 0;
}

void inchtocent(float x)
{
float cent=x*2.54; //1cm=2.54 inch so multipling is conversion
cout<<"\n"<<x<<" inches = "<<cent<<" centimetres."<<endl;//printing the reulsts
}
void centtoinch(float x)
{
float inch=x*0.393701;//1 inch= 0.393701 cm so multipling with that is conversion
cout<<"\n"<<x<<" centimeters = "<<inch<<" inches."<<endl;//printing the reulsts
}
look at your float remeber what gets promoted and demoted give you a hint change one of your variables you declared
1.
float cent=x*2.54; //1cm=2.54 inch so multipling is conversion

Should be :
float cent = x * 2.54f;

2.
float inch=x*0.393701;//1 inch= 0.393701 cm so multipling with that is conversion

Should be :
float inch = x * 0.393701f;
Do I need to change the float I still get a error?
Do I need to change the float I still get a error?

What do you mean? This is the solution.
Never mind Thank You for the help
Here is another program if you can help me please.

#include <iostream>
void getBalance(float);
using namespace std;
int main(int argc, char** argv)
{
float balance =0.0,min,max,deposit=0;
int a,b;
int i;
cout << "DEPOSIT:\t" ;
cin >> balance;
deposit =balance;
cout << "MINIMUM interest rate(in decimal form):\t";
cin >> min;
cout << "MAXIMUM interest rate(in decimal form):\t";
cin >> max;
a = ((max*100) - (min * 100))+1;

for(b=1;b<=a;b++)
{
switch(b)
{
case 1:cout << "Rate "<< b << "%:" << "\n";
for(i=1;i<=3;i++)
{
balance = balance + (balance *(min)) ;
cout << "\t\tYear"<< i <<":\t" << balance << "\n";
}
break;
case 2:cout << "Rate "<< b << "%:" << "\n";
min = min + 0.01;
balance = deposit;
for(i=1;i<=3;i++)
{
balance = balance + (balance *(min)) ;
cout << "\t\tYear"<< i <<":\t" << balance << "\n";
}
break;
case 3:cout << "Rate "<< b << "%:" << "\n";
balance = deposit;
for(i=1;i<=3;i++)
{
balance = balance + (balance *(max)) ;
cout << "\t\tYear"<< i <<":\t" << balance << "\n";
}
break;
}
}
cout << "Initial deposited amount =" ;getBalance(deposit) ;
return 0;
}
void getBalance(float deposit)
{
cout << deposit;
}

Warning 1 warning C4244: '=' : conversion from 'float' to 'int', possible loss of data c:\cpp8\chap 10\intermediate19 project\intermediate19 project\intermediate19.cpp 16 1 Intermediate19 Project

Warning 2 warning C4244: '=' : conversion from 'double' to 'float', possible loss of data c:\cpp8\chap 10\intermediate19 project\intermediate19 project\intermediate19.cpp 30 1 Intermediate19 Project

Error 3 error LNK1168: cannot open C:\Cpp8\Chap 10\Intermediate19 Project\Debug\Intermediate19 Project.exe for writing C:\Cpp8\Chap 10\Intermediate19 Project\Intermediate19 Project\LINK Intermediate19 Project

Topic archived. No new replies allowed.