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 


Multiplication calculator I made

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Negima
I post too much
Reputation: 6

Joined: 22 May 2007
Posts: 2221

PostPosted: Thu Apr 03, 2008 12:09 am    Post subject: Multiplication calculator I made Reply with quote

Hey guys, this is the first calculator I have made and I wanted to show you guys the source to give me some tips/tell me things to avoid.
I know I shouldn't use system("pause") API but I like how you have to press a key to continue, if there is another way I can do this please tell me.

Also, how can I get it so when you run the app you can choose between multiply/add/subtract/divide?

Code:
#include <iostream>

int main ()
{
   signed short MultiA, MultiB, Product;
   std::cout << "Please enter two numbers to multiply\n";
   std::cin >> MultiA;
   std::cin >> MultiB;
   system("pause");
   Product = MultiA * MultiB;
   std::cout << MultiA << "\n" <<"Multiplyed by: " << MultiB << "\n" <<"Equals: " << Product << "\n";
   system("pause");
   return 0;
}
Back to top
View user's profile Send private message Visit poster's website
Pseudo Xero
I post too much
Reputation: 0

Joined: 16 Feb 2007
Posts: 2607

PostPosted: Thu Apr 03, 2008 12:11 am    Post subject: Reply with quote

Just so you know, system("pause") isn't an API.
_________________
haxory' wrote:
can't VB do anything??
windows is programmed using VB right? correct me if im wrong.

so all things in windows you have like the start menu is a windows form too.
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Thu Apr 03, 2008 12:24 am    Post subject: Re: Multiplication calculator I made Reply with quote

Negima wrote:
Hey guys, this is the first calculator I have made and I wanted to show you guys the source to give me some tips/tell me things to avoid.
I know I shouldn't use system("pause") API but I like how you have to press a key to continue, if there is another way I can do this please tell me.

Also, how can I get it so when you run the app you can choose between multiply/add/subtract/divide?

Code:
#include <iostream>

int main ()
{
   signed short MultiA, MultiB, Product;
   std::cout << "Please enter two numbers to multiply\n";
   std::cin >> MultiA;
   std::cin >> MultiB;
   system("pause");
   Product = MultiA * MultiB;
   std::cout << MultiA << "\n" <<"Multiplyed by: " << MultiB << "\n" <<"Equals: " << Product << "\n";
   system("pause");
   return 0;
}


1. std::cin.ignore()
std::cin.sync()

2. make a loop that lets the user pick what they want and have it loop until the user specifies they don't want to do anything else.
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Thu Apr 03, 2008 1:51 am    Post subject: Reply with quote

What if user inputs letters? How about overflows? 0 isn't always EXIT_SUCCESS. std::endl is a nice thing too.

And why to hell you use short ints? -_- Even long long long .. long ints are sometimes too short...

Btw.. Why to pause before showing the result?

slovach wrote:
1. std::cin.ignore()
std::cin.sync()
Usually ppl sync() before ignoring to make sure there's nothing in the buffer...
Back to top
View user's profile Send private message
Zand
Master Cheater
Reputation: 0

Joined: 21 Jul 2006
Posts: 424

PostPosted: Thu Apr 03, 2008 2:28 am    Post subject: Reply with quote

Ask the user to select numbers to choose between division and multiplication then use a switch statement or if you want the user to type it out, do a stricmp.
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Thu Apr 03, 2008 2:57 am    Post subject: Reply with quote

Zand wrote:
Ask the user to select numbers to choose between division and multiplication then use a switch statement or if you want the user to type it out, do a stricmp.
If you're coding in C++, why to use stricmp?
Back to top
View user's profile Send private message
92Garfield
I'm a spammer
Reputation: 57

Joined: 20 Dec 2007
Posts: 5871
Location: Banana Republic Germany

PostPosted: Thu Apr 03, 2008 4:06 am    Post subject: Reply with quote

i like your avatar but make it smaller Razz
and remember the cube wont speak to you

_________________
Back to top
View user's profile Send private message
Negima
I post too much
Reputation: 6

Joined: 22 May 2007
Posts: 2221

PostPosted: Thu Apr 03, 2008 5:12 am    Post subject: Reply with quote

Jani wrote:
What if user inputs letters? How about overflows? 0 isn't always EXIT_SUCCESS. std::endl is a nice thing too.

And why to hell you use short ints? -_- Even long long long .. long ints are sometimes too short...

Btw.. Why to pause before showing the result?

slovach wrote:
1. std::cin.ignore()
std::cin.sync()
Usually ppl sync() before ignoring to make sure there's nothing in the buffer...
What amount of memory would you recommend for these variables?
Quote:
Ask the user to select numbers to choose between division and multiplication then use a switch statement or if you want the user to type it out, do a stricmp.
How would I do this?
Back to top
View user's profile Send private message Visit poster's website
Zand
Master Cheater
Reputation: 0

Joined: 21 Jul 2006
Posts: 424

PostPosted: Thu Apr 03, 2008 7:34 am    Post subject: Reply with quote

Uh..

Code:

#include <iostream>

enum CalcMode
{
  MODE_MULTIPLICATION = 1,
  MODE_DIVISION = 2,
  MODE_ADDITION = 3,
  MODE_SUBTRACTION = 4,
};

int main ()
{
   signed short NumA, NumB, Product, Mode;
   char cMessage[255] = "Please enter two numbers to ";

   std::cout << "Please choose calculator mode.\n1. Multiplication\n2. Division\n3. Addition\n4. Subtraction\n\n";
   std::cin >> Mode;

   std::cout << "\n";

   switch ( Mode )
   {

      case MODE_MULTIPLICATION:
         strcat(cMessage, "multiply\n");
         break;

      case MODE_DIVISION:
         strcat(cMessage, "divide\n");
         break;

      case MODE_ADDITION:
         strcat(cMessage, "add\n");
         break;

      case MODE_SUBTRACTION:
         strcat(cMessage, "subtract\n");
         break;

      default:
         std::cout << "No such mode\n\n";
         system("pause");
         return 0;
         break;
   }

   std::cout << cMessage << "\n";

   std::cin >> NumA;
   std::cin >> NumB;

   std::cout << "\n";
   //system("pause");

   switch ( Mode )
    {
      case MODE_MULTIPLICATION:
         Product = NumA * NumB;
         break;

      case MODE_DIVISION:
         Product = NumA / NumB;
         break;

      case MODE_ADDITION:
         Product = NumA + NumB;
         break;

      case MODE_SUBTRACTION:
         Product = NumA - NumB;
         break;
   }

   //Product = NumA * NumB;
   //std::cout << NumA << "\n" <<"Multiplyed by: " << NumB << "\n" <<"Equals: " << Product << "\n";
   std::cout << "Answer is : " << Product << "\n\n";

   system("pause");
    return 0;
}


psuedo code. I'm using system pause as it's your code. This can probably be made into much more efficient code.
Back to top
View user's profile Send private message
DoomsDay
Grandmaster Cheater
Reputation: 0

Joined: 06 Jan 2007
Posts: 768
Location: %HomePath%

PostPosted: Thu Apr 03, 2008 9:39 am    Post subject: Reply with quote

The code looks well, but I think you should use printf() though, it's easier to work with.
P.S.
Code:
@echo off
title Calc

:start
cls
echo ===============
echo Enter argument:
set /p arg=
set /a arg=%arg%
echo 
echo Result: %arg%
echo ===============
pause > nul
goto start
Back to top
View user's profile Send private message
WafflesFTW
Expert Cheater
Reputation: 0

Joined: 21 Mar 2008
Posts: 131

PostPosted: Thu Apr 03, 2008 3:40 pm    Post subject: Reply with quote

printf is C. I prefer cout.
You should expand your program to make decisions based on user input, like ask them to insert and expression. It can be very helpful to make as it teaches a lot about arrays, etc
Back to top
View user's profile Send private message AIM Address
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Fri Apr 04, 2008 3:00 am    Post subject: Reply with quote

Negima wrote:
What amount of memory would you recommend for these variables?
Infinite... I mean dynamic :)
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
Page 1 of 1

 
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