Music ku

Tuesday, March 29, 2011

Exercises no 3

you are required to do program that will execute the multiply
or divided operation is based on the user's choice. You
must see Switch...Case statement Output:













Answer:

#include <iostream.h>
main ()
{
  //Declare variable
  int num1,num2,selection,total_multiply,total_divided;

  cout<<"masukkan nombor satu";
  cin>>num1;
  cout<<"masukkan nombor dua";
  cin>>num 2;
  cout<<"masukkan pilihan anda";
  cin>>selection;
  Switch(selection)
{
case 1:(selection=1)
  total_multiply=num1*num2;
  cout<<hasil darab"<<num1<<"dan<<num2<<"
  ialah"<<total_multiply endl;
  break;
case 2:(selection=2)
  total_divided=num1/num2;
  cout<<hasil_bahagi"<<num<<"dan<<num2<<"
  ialah"<<total_divide endl;
  break;
}
return 0;
}

No comments:

Post a Comment