Thursday, November 22, 2012

C++ exercise 1

Write a program that display a menu as following:

Press 1: to let user enter 2 numbers and print their
multiplication value
Press 2: to let user enter a range of 2 numbers and the program
will calculate the summation of all numbers in this Range.
Press 3: to let user enter many numbers until a negative value
entered then the program print the Maximum and Minimum
value entered.
Press 0: to Exit program.
________________________________________________________________________





#include<iostream.h>

#include <cstdlib> // included to use exit(0)

int main()

{

    int x,y,z,c,t;t=0;z=0;

    cout<<" 2Press 1: to enter 2 numbers and get their multiplication.\n " ;

    cout<<"Press 2: to enter range of 2 numbers and get summation of this range.\n ";

    cout<<"Press 3: to enter many numbers value and get thier Maximum and Minimum. \n ";

    cout<<"Press 0: to Exit program. \n ";

  

    cin>>x;

    if(x==1)

    {

        cout<<"Enter two No.\n2";

        cin>>y;

        cin>>z;

        c=y*z;

        cout<<endl<<c;

    }

        else if (x==2)

        {

            cout<<"Enter two numbers\n";

            cin>>y>>z;
            if(y<z)

             for(y;y<=z;y++)

            t=y+t;
           
            else
            for(y;y>=z;y--)

            t=y+t;

            cout<<t;

        }

        else if(x==3)

            {

      

            cin>>y;

            c=y;

            while(y>0)

              {

                  if(y>z)  

                  z=y;

                  else if(y<c)

                      c=y;

                  cin>>y;

               }

            cout<<z<<endl<<c;

            }

  

        else if(x==0)

            exit(0);  

        else

        cout<<"Go To Hell :D\n";

return 0;

}

No comments:

Post a Comment