c1

petak, 13. travnja 2012.

9. Simple C++ Program - Tutorial


/*
In this program we use calculating operations like adding, multiplying, dividing and subtracting numbers...
*/


#include <iostream>
using namespace std;
int main()
{
    int option=1;
    while(option!=0){
    double number1;
    double number2;
    int option2;
    cout<<"Choose the option that you want:  "<<endl;
    cout<<"1)  Add two numbers...  "<<endl;
    cout<<"2)  Subtract two numbers...  "<<endl;
    cout<<"3)  Multiply two numbers...  "<<endl;
    cout<<"4)  Divide two numbers...  "<<endl;
    cout<<"0)  Exit... "<<endl;
    cin>>option;
    if(option!=0){
    cout<<endl<<"Enter two numbers:   "<<endl;
    cin>>number1;
    cin>>number2;
                 }
    cout<<endl;  
    switch(option){
      case 1:{
       cout<<number1<<" + "<<number2<<" = "<<number1+number2<<endl;
       break;
                        }
      case 2:{
       cout<<number1<<" - "<<number2<<" = "<<number1-number2<<endl;
       break;
                        }
      case 3:{
       cout<<number1<<" x "<<number2<<" = "<<number1*number2<<endl;
       break;
                        }
      case 4:{
       cout<<number1<<" : "<<number2<<" = "<<number1/number2<<endl;
       break;
                        }      
}
    cout<<endl;
                }          
    cout<<endl<<endl;
    system("PAUSE");
    return EXIT_SUCCESS;
}

code

after we run and use program

Nema komentara:

Objavi komentar