Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


C++ Calculator | Difficulty: MIND CRUSHINGLY AVERAGE
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Hieroglyphics
I post too much
Reputation: 0

Joined: 06 Dec 2007
Posts: 2007
Location: Your bedroom

PostPosted: Sun Nov 23, 2008 4:24 pm    Post subject: C++ Calculator | Difficulty: MIND CRUSHINGLY AVERAGE Reply with quote

Here it is 100% me:

Code:
#include <cstdlib>
#include <math.h>
#include <stdio.h>
#include <iostream>
#include <string>
#define PI 3.14159265
 
using namespace std;

int main()
{
    int first, second, answer, circumference, area, perimeter, third, aplusb, bOut, twosides, total;
   double pathagorus, peremeter;
    char menu;
    for (;;){
    do {
    cout << "Welcome to Hiero Calc!\n";
    cout << "by Hieroglyphics\n\n";
    cout << "Please press one of the following on your keyboard:\n";
    cout << "1 - Addition\n";
    cout << "2 - Subtraction\n";
    cout << "3 - Division\n";
    cout << "4 - Multiplication\n";
    cout << "5 - Circles\n";
    cout << "6 - Squares\n";
    cout << "7 - Rectangles\n";
   cout << "8 - Triangles\n";
   cout << "9 - Trapezoid\n";
    cin >> menu;
    }
    while ( menu < '1' || menu > '9');
    switch (menu) {
           case '1':
                cout << "Enter the first number you would like to add\n";
                cin >> first;
                cout << "Enter the second number you would like to add\n";
                cin >> second;
            answer = first + second;
                cout << first << "+" << second << "=" << answer;
                cout << "\n";
                break;
           case '2':
                cout << "Please enter a number to subtract from\n";
                cin >> first;
                cout << "Another number to be subtracted\n";
                cin >> second;
            answer = first - second;
                cout << first << "-" << second << "=" << answer;
                cout << "\n";
                break;
           case '3':
                cout << "Please enter a number to divide from\n";
                cin >> first;
                cout << "Please enter the second number to be divided\n";
                cin >> second;
            answer = first / second;
                cout << first << "/" << second << "=" << answer;
                cout << "\n";
                break;
           case '4':
                cout << "Please enter a number to multiply\n";
                cin >> first;
                cout << "Please enter the second number to be multiplied\n";
                cin >> second;
            answer = first * second;
                cout << first << "*" << second << "=" << answer;
                cout << "\n";
                break;
           case '5':
                cout << "Enter Radius\n";
            cin >> first;
            circumference = 2 * first * PI;
            area = first * first * PI;
            cout << "Circumference = " << circumference << ".\n";
            cout << "Area = "  << area << ".\n";
                break;
           case '6':
            cout << "Enter the length of one side\n";
            cin >> first;
            area = first * first;
            perimeter = first * 4;
            cout << "Perimeter = " << perimeter << ".\n";
            cout << "Area = " << area << ".\n";
                break;
           case '7':
                cout << "Enter the length of one side\n";
            cin >> first;
            cout << "Enter the length of the second side\n";
            cin >> second;
            area = first * second;
            perimeter = (first * 2) + (second * 2);
            cout << "Perimeter = " << perimeter << ".\n";
            cout << "Area = " << area << ".\n";
                break;
         case '8':
                cout << "Enter the height\n";
            cin >> first;
            cout << "Enter the base\n";
            cin >> second;
            area = (first + second)/2;
             pathagorus = (second*second)+(first*first);
            peremeter = sqrt( pathagorus );
            cout << "Perimeter = " << peremeter << ".\n";
            cout << "Area = " << area << ".\n";
                break;   
         case '9':
                cout << "Enter the length of the top\n";
            cin >> first;
            cout << "Enter the length of the bottom\n";
            cin >> second;
            cout << "Enter the height\n";
            cin >> third;
            aplusb = (first + second)/2;
            area = third*aplusb;
            perimeter = first + second;
            bOut = (second-first)/2;
            pathagorus = (bOut*bOut)+(third*third);
            peremeter = sqrt( pathagorus );
            twosides = 2*peremeter;
            total = perimeter+twosides;
            cout << "Perimeter = " << total << ".\n";
            cout << "Area = " << area << ".\n";
                break;
                }
 
}
return 0;


}

_________________

Back to top
View user's profile Send private message AIM Address MSN Messenger
kitterz
Grandmaster Cheater Supreme
Reputation: 0

Joined: 24 Dec 2007
Posts: 1268

PostPosted: Sun Nov 23, 2008 4:32 pm    Post subject: Reply with quote

hmmm why not make a real calculator?

one that you put as input, say

"1+1" ?

_________________
Back to top
View user's profile Send private message Send e-mail
Hieroglyphics
I post too much
Reputation: 0

Joined: 06 Dec 2007
Posts: 2007
Location: Your bedroom

PostPosted: Sun Nov 23, 2008 4:38 pm    Post subject: Reply with quote

well its pretty much the same, if you noticed you can input 1+1 and it will say the answer
_________________

Back to top
View user's profile Send private message AIM Address MSN Messenger
Spawnfestis
GO Moderator
Reputation: 0

Joined: 02 Nov 2007
Posts: 1746
Location: Pakistan

PostPosted: Sun Nov 23, 2008 4:44 pm    Post subject: Reply with quote

Well glad to know I can now delete this from my own forum. Rolling Eyes
_________________

CLICK TO HAX MAPLESTORAY ^ !!!!
Back to top
View user's profile Send private message Send e-mail MSN Messenger
BirdsEye
Advanced Cheater
Reputation: 0

Joined: 05 Apr 2008
Posts: 94

PostPosted: Sun Nov 23, 2008 6:06 pm    Post subject: Reply with quote

Good job. I'm soon going to release a Win32 Calculator which basically is an imitation of the default 'Calculator.' I just have to polish a few things up.
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Sun Nov 23, 2008 6:52 pm    Post subject: Reply with quote

This has left me truly horrified to see what you think is advanced.
Back to top
View user's profile Send private message
Overload
Master Cheater
Reputation: 0

Joined: 08 Feb 2008
Posts: 293

PostPosted: Sun Nov 23, 2008 7:45 pm    Post subject: Reply with quote

slovach wrote:
This has left me truly horrified to see what you think is advanced.

That's exactly what I thought.

_________________
Blog

Quote:
Rhys says:
you can be my maid
Rhys says:
ill buy you a french maid outfit
Tyler says:
Sounds good
Rhys says:
ill hold you to that
Back to top
View user's profile Send private message MSN Messenger
nog_lorp
Grandmaster Cheater
Reputation: 0

Joined: 26 Feb 2006
Posts: 743

PostPosted: Mon Nov 24, 2008 7:24 am    Post subject: Reply with quote

Implement a reverse polish notation calculator.
http://en.wikipedia.org/wiki/Reverse_polish_notation

Also, implement arbitrary precision arithmetic.

_________________
Mutilated lips give a kiss on the wrist of the worm-like tips of tentacles expanding in my mind
I'm fine accepting only fresh brine you can get another drop of this yeah you wish
Back to top
View user's profile Send private message
Niels8500
Grandmaster Cheater
Reputation: 0

Joined: 19 Sep 2007
Posts: 859
Location: The Netherlands

PostPosted: Mon Nov 24, 2008 7:28 am    Post subject: Reply with quote

1 Error
Back to top
View user's profile Send private message
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Mon Nov 24, 2008 2:23 pm    Post subject: Reply with quote

nog_lorp wrote:
Implement a reverse polish notation calculator.
http://en.wikipedia.org/wiki/Reverse_polish_notation


Code:

#define ISDIGIT( x )   ( x >= '0' && x <= '9' )
#define CHARTONUM( x )   ( x - '0' )
#define ISOPERAND( x )   ( x == '+' || x == '-' || x == '*' || x == '/' )

bool parseRPN( char *szExpression, int *pResult )
{
   std::stack< int > Operands;

   int currentNum = 0;
      
   for( unsigned i = 0; i < strlen( szExpression ); i++ ) {
      if( szExpression[ i ] == ' ' ) {
         if( i == 0 )
            return false;
         else if( ISOPERAND( szExpression[ i - 1 ] ) )
            continue;
            
         Operands.push( currentNum );
         currentNum = 0;
         continue;
      }

      if( ISDIGIT( szExpression[ i ] ) ) {      
         currentNum = currentNum * 10 + CHARTONUM( szExpression[ i ] );
         continue;
      }

      if( ISOPERAND( szExpression[ i ] ) ) {
         if( i == 0 ||
            szExpression[ i - 1 ] != ' ' )
            return false;

         currentNum = Operands.top( );
         Operands.pop( );

         currentNum = DoOp( szExpression[ i ], Operands.top( ), currentNum );

         Operands.pop( );
         Operands.push( currentNum );

         currentNum = 0;
         continue;
      }
   }

   *pResult = Operands.top( );

   return true;
}

int DoOp( char cOperation, int nOperandOne, int nOperandTwo )
{
   int nRet;

   switch( cOperation ) {
      case '+':
         nRet = nOperandOne + nOperandTwo;
         break;
      case '-':
         nRet = nOperandOne - nOperandTwo;
         break;
      case '*':
         nRet = nOperandOne * nOperandTwo;
         break;
      case '/':
         nRet = nOperandOne / nOperandTwo;
         break;
      DEFAULT_UNREACHABLE;
   }

   return nRet;
}


Could maybe be optimized a little, but eh.

Took me roughly 10 minutes, after reading.

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
nog_lorp
Grandmaster Cheater
Reputation: 0

Joined: 26 Feb 2006
Posts: 743

PostPosted: Mon Nov 24, 2008 3:26 pm    Post subject: Reply with quote

Nice. Usually they keep their state - I would be able to run "5 3 +" and then "8 -" and get 0, and keep working from there. That shouldn't be hard to do at all though.
_________________
Mutilated lips give a kiss on the wrist of the worm-like tips of tentacles expanding in my mind
I'm fine accepting only fresh brine you can get another drop of this yeah you wish
Back to top
View user's profile Send private message
TehBestNewbZ
Expert Cheater
Reputation: 0

Joined: 28 Jul 2006
Posts: 109

PostPosted: Mon Nov 24, 2008 3:46 pm    Post subject: Reply with quote

Average? It's pretty basic.
Back to top
View user's profile Send private message
nog_lorp
Grandmaster Cheater
Reputation: 0

Joined: 26 Feb 2006
Posts: 743

PostPosted: Mon Nov 24, 2008 6:01 pm    Post subject: Reply with quote

Next up: algebraic expression evaluator with correct order of operations!

Bonus points if you allow function definition in the form of "abc(args) = <expression in terms of args"

_________________
Mutilated lips give a kiss on the wrist of the worm-like tips of tentacles expanding in my mind
I'm fine accepting only fresh brine you can get another drop of this yeah you wish
Back to top
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Mon Nov 24, 2008 6:08 pm    Post subject: Reply with quote

Add boolean algebra too
Back to top
View user's profile Send private message MSN Messenger
nog_lorp
Grandmaster Cheater
Reputation: 0

Joined: 26 Feb 2006
Posts: 743

PostPosted: Mon Nov 24, 2008 7:40 pm    Post subject: Reply with quote

Matrix algebra would be more useful.
_________________
Mutilated lips give a kiss on the wrist of the worm-like tips of tentacles expanding in my mind
I'm fine accepting only fresh brine you can get another drop of this yeah you wish
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites