Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Second script its a calculator


eltony
 Share

Recommended Posts

lol so here is my second c++ script its an actual calculator hahaha :)
```
#include using namespace std;

int main(void)
{

    system("TITLE Calculator");
    system("COLOR 2");
    char cChar;
    double dfirstnumber;
    double dsecondnumber;
    char cdoagain;

    do
    {
        system("CLS");
        cout << "please enter the first number that you would like to use"
            << endl;
        cin >> dfirstnumber;
        cout << "please enter the operation that you would like to complete"
            << " (+,-,* or /)" << endl;
        cin >> cChar

        cout << "please enter the second number you would like to use"
            << endl;

        Switch (cChar)
        {
        case '+':
            cout << " The answer is: " << dfirstnumber << " + " <<
                dsecondnumber << " = " << (dfirstnumber + dsencondnumber)
                << endl;
            break;
        case '-':
            cout << " The answer is: " << dfirstnumber << " - " <<
                desencondnumber << " = " << (dfirstnumber - dsecondnumber)
                << endl;
            break;
        case '*':
            cout << " The answer is: " << dfirstnumber << " * " <<
                dsencondnumber << " = " << (dfirsnumber * dsencondnumber)
                << endl;
              break;
        case 'x':
            cout << " The answer is: " << dfirstnumber << " x " <<
                dsencondnumber << " = " (dfirstnumber x dsencondnumber)
                << endl;
              break;
        case 'X':
            cout << " The answer is: " << dfirstnumber << " X " <<
                dsencondnumber << " = " (dfirstnumber X dsencondnumber)
                << endl;   
              break;   
        case '/':
            if(dsecondnumber == 0) {
                cout << " That is an invalid operation" << endl;
            )else{
            cout << " The answer is: " << dfirstnumber << " x " <<
                dsencondnumber << " = " (dfirstnumber x dsencondnumber)
                << endl;
            }
            break;
        default:
            cout << "That is an invalid operation" << endl;
            break;
        }
        cout << "would you like to start again? ( y or n)" << enld;
        cin >> cDoagain;
    }while (cDoagain == 'Y' or cDogain == 'y');
    system("PAUSE") ;
    return 0;
    }

```
Link to comment
Share on other sites

Looks kinda odd when you get a endl when you're gonna type in the number, I prefer it like this:

Please enter the operation that you would like to complete: + (then endl)

Please enter the first number you would like to use: 15 (then endl)

Please enter the second number you would like to use: 22 (then endl)

The answer of 15 + 22 is 37.

Although I guess it's kinda a design choice. Good job otherwise. :P

If you want another challenge on something to do that I had to do in school, make a game where the computer randomly generates a number between x and y (The player chooses what numbers), and then you need to guess what number it generated. If it's higher, it should say it's higher, if its lower it should say it's lower. :P

So lets say the players says 1 and 50, so a number between 1 and 50 will be generated and you then need to guess what it is.
Link to comment
Share on other sites

@eltony:

> wow lols so pretty much it needs to have a random number between 1 and 50 to generate and youll have to guess umm lols ill figure it out thanks for the challenge

oh and good point on the endl lols well i notice alot of my class mates wrote it differently well like u said depends on design lols as long as it compiles for me im good lols
Link to comment
Share on other sites

well i think i got it i mean i got errors but ye i think its right im not sure but i added all that it needs i think idk i got head ache```
#include
#include
using namespace std;

int mian() {
    int random;
    int guess;

    srand(static_cast(time(0)));
    random = rand()%50+1;

    cout <<"Guess my number! (1-50)\n";

    while(guess != random) {
                cin >> guess;
                cin.ignore();
                if (guess < random) {
                          cout << "To Low \n"
                if (guess > random) {
                          cout <<"To High \n"
                          }
                if (guess == random) {
                          cout <<"You Won!" << random <<".\n";
                          cin.get();
                          }
                          }
                          }

```
Link to comment
Share on other sites

Here's the one I made, it was quite a while ago so forgive me for the derp code, I took the time to translate the ints and the things you see in game to English at least, but the comments remain Swedish as I am lazy. ;P

>! ```
#include
#include
//9 September 2010
using namespace std;
>! int main(int argc, char *argv[])
{
    int number,random,loop,guesses,to,from;
    number=0;
    random=0;
    loop=1;
    to=0;
    from=0;
    guesses=0; //När du gissar fel sÃ¥ ökar denna int med 1, ifall du vinner skrivs det ut hur mÃ¥nga gÃ¥nger du hade fel.
    cout<<"The computer will randomly select a number between the two you will specify and you need to guess which one it is!"<>from;
    cout<>to;
    cout<>number; //Talet du skriver in ska bli samma som det som datorn har gissat.
          cout<random)
          {
              cout<<"The number is lower."< I'm sure you can figure it out.

```
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...