How to Create Temperature Conversion Program using C++

Ok today Im gonna to show you,How to make simple Temperature Conversion Program using C++,its easy and Pretty nice

here the codes,Now play time 😉

#include <iostream>
int main()
{
int celsius,fahrenheit;
std::cout<<“\nEnter Temperature in Faherenite: “;
std::cin>>fahrenheit;
celsius=5*(fahrenheit-32)/9;
std::cout<<“Temperature is “;
std::cout<<celsius;
std::cout<< ” Degrees celsius”;
std::cout<<“\nEnter Any key to Exit “;
return 0;
}

celsius=5*(fahrenheit-32)/9;

if the parentheses were not used initially 5 would be multiplied with the variable fahreheit. Because we want to subtract 32 from fahreheit    initially we need to use brackets.

without the parentheses,the multiplication would be carried out first,since * has higher priority than -.with the parentheses  are carried out first.

what about the precedence of the * and / signs? when two arithmetic operators have the same precedence,the one on the left is executed first,so the multiplication will be carried out next;then division.precedence and parentheses are normally applied this same way in  algebra and other computer languages.so their use probably seems quite natural.however,precedence is an important topic in C++.

Advertisements
Tagged with: , , , ,
Posted in lesson

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: