#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 ==========
#include<iostream>
#include<stdlib.h>//for exit
usingnamespace 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
}
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