EnglishFrenchGermanSpainItalianDutchPortugueseRussianKoreanJapaneseArabic Chinese Simplified

Saturday, April 16, 2011

Calculator (C++)

This code (program) allows you to choose what calculations you want. Like Addition and Multiplication. It uses the switch statement. this is only a very simple calculator and can only calculate two numbers at a time. Now it uses a loop and quits when you want it to.


#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
    double num;
    double num2;
    char choice;
    for (;;){
     do {
    cout<<"Welcome to thejoshcalculator. V1.5\n";
    cout<<"Please choose an option by entering the number, press q to quit\n";
    cout<<"1 - Addition\n";
    cout<<"2 - Subtraction\n";
    cout<<"3 - Division\n";
    cout<<"4 - Multiplication\n";
    cout<<"5 - Help\n";
    cout<<"6 - About This Program\n";
    cout<<"7 - Updates to this program\n";
    cin>>choice;
    } while ( choice < '1' || choice > '7' && choice != 'q');
    if (choice == 'q') break;
    switch (choice) {
           case '1':
                cout<<"Please enter a number\n";
                cin>>num;
                cout<<"Another number to be added\n";
                cin>>num2;
                cout<<num + num2;
                cout<<"\n";
                break;
           case '2':
                cout<<"Please enter a number\n";
                cin>>num;
                cout<<"Another number to be subtracted\n";
                cin>>num2;
                cout<<num - num2;
                cout<<"\n";
                break;
           case '3':
                cout<<"Please enter a number\n";
                cin>>num;
                cout<<"Another one to be divided\n";
                cin>>num2;
                cout<<num / num2;
                cout<<"\n";
                break;
           case '4':
                cout<<"Please enter a number\n";
                cin>>num;
                cout<<"Another one to be multiplied\n";
                cin>>num2;
                cout<<num * num2;
                cout<<"\n";
                break;
           case '5':
                cout<<"This is a simple calculator made by me - Josh.\n";
                cout<<"To select an option, type the number next to the option and press enter\n";
                cout<<"E.G. for division, you would type 3 and press enter.\n";
                cout<<"\n";
                break;
           case '6':
                cout<<"thejoshcalculator, made by Joshua Griggs - Copyright 2007. :)\n";
                cout<<"Feedback would be nice - joshieboy06@hotmail.com also, what programmes\n";
                cout<<"do people need. Please give me ideas for programs. Bye!!\n";
                cout<<"\n";
                break;
           case '7':
                cout<<"Updates include:  -double variable instead of int, so that decimals can be used.\n";
                cout<<"                  -do while loop so that you can exit the program yourself\n";
                cout<<"\n";
                break;
           default:
                    cout<<"That is not an option";
                   
                }

}
return 0;


}

Artikel Terkait:

Comments :

0 comments to “Calculator (C++)”

Post a Comment

 

Copyright © 2009 by Learn Technology

Template by Blogger Templates | Powered by Blogger