Posted by: Sourav | August 2, 2012

Input numbers with cin in c++


#include<iostream>
using namespace std;

int main(){
    
   /* int number;
    cin >> number;
    cout << number<<endl;*/
   
   /*int number1,number2;
   
   cin >>number1>>number2;
   
   cout <<“Number1: “<<number1<<endl<<“Number2: “<<number2<<endl; */
   
   int number1,number2,result;
   
   cout<<“Please enter the first number: “;
   cin>>number1;
   cout<<“Please enter the second number: “;
   cin>>number2;
   string operator1;
   cout<<“Please enter the operator: “;
   cin>>operator1;
   if(operator1==”+”)
   
   {
   result=number1+number2;
   
   cout<<number1<<” + “<<number2<<” = “<<result<<endl;
   }
   if(operator1==”-“)
    {
   result=number1-number2;
   
   cout<<number1<<” – “<<number2<<” = “<<result<<endl;
   }
    return 0;
    
    
    
}

Advertisements

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

Categories

%d bloggers like this: