Thursday, 28 February 2013

Tutorial Pembuatan Caculator di C++

Ini Scrip pembuatannya.....





  1. #include <cstdlib>
  2. #include <iostream>
  3. using namespace std;
  4. int main()
  5. {
  6.     double num;
  7.     double num2;
  8.     char choice;
  9.     for (;;){
  10.      do {
  11.     cout<<"Welcome to thejoshcalculator. V1.5\n";
  12.     cout<<"Please choose an option by entering the number, press q to quit\n";
  13.     cout<<"1 - Addition\n";
  14.     cout<<"2 - Subtraction\n";
  15.     cout<<"3 - Division\n";
  16.     cout<<"4 - Multiplication\n";
  17.     cout<<"5 - Help\n";
  18.     cout<<"6 - About This Program\n";
  19.     cout<<"7 - Updates to this program\n";
  20.     cin>>choice;
  21.     } while ( choice < '1' || choice > '7' && choice != 'q');
  22.     if (choice == 'q') break;
  23.     switch (choice) {
  24.            case '1':
  25.                 cout<<"Please enter a number\n";
  26.                 cin>>num;
  27.                 cout<<"Another number to be added\n";
  28.                 cin>>num2;
  29.                 cout<<num + num2;
  30.                 cout<<"\n";
  31.                 break;
  32.            case '2':
  33.                 cout<<"Please enter a number\n";
  34.                 cin>>num;
  35.                 cout<<"Another number to be subtracted\n";
  36.                 cin>>num2;
  37.                 cout<<num - num2;
  38.                 cout<<"\n";
  39.                 break;
  40.            case '3':
  41.                 cout<<"Please enter a number\n";
  42.                 cin>>num;
  43.                 cout<<"Another one to be divided\n";
  44.                 cin>>num2;
  45.                 cout<<num / num2;
  46.                 cout<<"\n";
  47.                 break;
  48.            case '4':
  49.                 cout<<"Please enter a number\n";
  50.                 cin>>num;
  51.                 cout<<"Another one to be multiplied\n";
  52.                 cin>>num2;
  53.                 cout<<num * num2;
  54.                 cout<<"\n";
  55.                 break;
  56.            case '5':
  57.                 cout<<"This is a simple calculator made by me - Josh.\n";
  58.                 cout<<"To select an option, type the number next to the option and press enter\n";
  59.                 cout<<"E.G. for division, you would type 3 and press enter.\n";
  60.                 cout<<"\n";
  61.                 break;
  62.            case '6':
  63.                 cout<<"thejoshcalculator, made by Joshua Griggs - Copyright 2007. :)\n";
  64.                 cout<<"Feedback would be nice - joshieboy06@hotmail.com also, what programmes\n";
  65.                 cout<<"do people need. Please give me ideas for programs. Bye!!\n";
  66.                 cout<<"\n";
  67.                 break;
  68.            case '7':
  69.                 cout<<"Updates include:  -double variable instead of int, so that decimals can be used.\n";
  70.                 cout<<"                  -do while loop so that you can exit the program yourself\n";
  71.                 cout<<"\n";
  72.                 break;
  73.            default:
  74.                     cout<<"That is not an option";
  75.                 }
  76. }
  77. return 0;
  78. }

No comments:

Post a Comment