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]A simple calc

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

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Sat Mar 22, 2008 4:06 am    Post subject: [C]A simple calc Reply with quote

it only do the following:
+
-
/
*

2 numbers

i didn't invest much time on it, i could of make it do more numbers and shit.

for those who loves C, there's a tiny bug, try fixing it.

when you 5/2 it doesn't show 2.5, only 2

Code:
#include "windows.h" //uses windows;
#include "stdio.h"

//i really don't know what's the diff between scan/printf to scan/printf_s
//i'm using it just for the sake of the warnings i get @ compile

void main();

//**********Main Functions**********\\

int Add(int fNumber,int sNumber)
{
   return fNumber+sNumber;
}

int Sub(int fNumber,int sNumber)
{
   return fNumber-sNumber;
}

int Mul(int fNumber, int sNumber) //function Mul(fNumber,sNumber:integer):integer;
{ //begin
   return fNumber*sNumber; //result:=fNumber*sNumber;
} //end;

int Div(int fNumber, int sNumber)
{
   return fNumber/sNumber;
}

//**********Main Functions**********\\

void DoAnother() //Thanks to irwin for helping me fix the instant close problem and the %c
{
   //bool TF;
   char lol,sc;

   //TF = true;   

   printf("Would you like to try another number ?\n");
   printf("Y = Yes, N = No...\n\n"); //WriteLn('Y = Yes, N = No...');

   /*while(TF == true)
   {
         if(GetAsyncKeyState(0x59)) //59 = Y
         {
            main();
            TF = false;
         }
         else if(GetAsyncKeyState(0x4E)) // 4E = N
         {
            ExitProcess(0);
         }
   }*/
   
   scanf_s("%c",&sc); //MSVC++ 2k8 warned me to use scanf_s

   lol = getchar();

   switch(lol)
   {
   case 'Y': case 'y':
      main();
      break;
   case 'N': case 'n':
      ExitProcess(0);
   default:
      printf("\nThere's no such option\n\n");
      DoAnother();
      break;
   }   
}

void main()
{
   int a,b,sum,Choice;
   DWORD ms=50;

   printf("Insert First Number:");
   scanf_s("%d",&a); //MSVC++ 2k8 warned me to use scanf_s
   printf("Insert Second Number:");
   scanf_s("%d",&b); //MSVC++ 2k8 warned me to use scanf_s

   printf("\nWhat would you like to to ?\n");
   printf("1:Substracte\n");
   printf("2:Addition\n");
   printf("3:Multiply\n");
   printf("4:Devide\n");
   scanf_s("%d",&Choice); //MSVC++ 2k8 warned me to use scanf_s
   
   /*if(Choice == 2)
   {
          sum = Add(a,b);
           printf("the sum of %d + %d is %d\n\n",a,b,sum);

           Sleep(ms);
           DoAnother();
   }
   else if(Choice == 1)
   {
      sum = Sub(a,b);
      printf("the sum of %d + %d is %d\n\n",a,b,sum);

      Sleep(ms);
      DoAnother();
   }
   else if((Choice > 2 || 1) || (Choice < 2 || 1))
   {
      printf_s("There's no such option\n\n");
      main();
   }*/

   switch(Choice)
   {
   case 1:
      sum = Sub(a,b);
      printf("The sum of %d - %d is %d\n\n",a,b,sum);

      Sleep(ms);
      DoAnother();
      break;
   case 2:
      sum = Add(a,b);
       printf("The sum of %d + %d is %d\n\n",a,b,sum);

       Sleep(ms);
       DoAnother();
       break;
   case 3:
      sum = Mul(a,b);
      printf("The sum of %d * %d is %d\n\n",a,b,sum);

      Sleep(ms);
      DoAnother();
      break;
   case 4:
      sum = Div(a,b);
      printf("The sum of %d / %d is %d\n\n",a,b,sum);

      Sleep(ms);
      DoAnother();
      break;
   default:
      printf("There's no such option\n\n");
      main();
      break;
   }
}
Back to top
View user's profile Send private message
Estx
Expert Cheater
Reputation: 0

Joined: 04 Mar 2008
Posts: 172

PostPosted: Sat Mar 22, 2008 5:02 am    Post subject: Reply with quote

To fix the bug, change int to a double. Don't forget to modify precision where needed.

Oh, divide and subtract have typo's lol. Just pointing it out Very Happy
Back to top
View user's profile Send private message
Anden100
Grandmaster Cheater
Reputation: 0

Joined: 20 Apr 2007
Posts: 668

PostPosted: Sat Mar 22, 2008 5:24 am    Post subject: Re: [C]A simple calc Reply with quote

Rot1 wrote:
for those who loves C, there's a tiny bug, try fixing it.

when you 5/2 it doesn't show 2.5, only 2


well... i wouldnt call that a "bug"... its just because, integer values is always rounded...
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sat Mar 22, 2008 9:40 am    Post subject: Reply with quote

The _s's at the end are simply their for CRT security enhancements to prevent buffer overflows, etc.

if you looked it up you would of found that out in about 30 seconds...

_________________
Back to top
View user's profile Send private message
spectrum
Expert Cheater
Reputation: 0

Joined: 27 Mar 2007
Posts: 143

PostPosted: Sat Mar 22, 2008 10:22 am    Post subject: Reply with quote

It gives me an error, it says:"main must return int".
_________________
C++ {||||||||||}
ASM {||||||||||}
Back to top
View user's profile Send private message
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Sat Mar 22, 2008 11:34 am    Post subject: Re: [C]A simple calc Reply with quote

Anden100 wrote:
Rot1 wrote:
for those who loves C, there's a tiny bug, try fixing it.

when you 5/2 it doesn't show 2.5, only 2


well... i wouldnt call that a "bug"... its just because, integer values is always rounded...


i acutally made the function float but it still didn't work, i got tired from trying.

spectrum wrote:
It gives me an error, it says:"main must return int".


idk about you, but i'm using MSVC++ 2008 Express Edition (Registered) and it compiles.
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Sat Mar 22, 2008 2:06 pm    Post subject: Reply with quote

spectrum wrote:
It gives me an error, it says:"main must return int".


Whatever compiler you're using is nice enough to complain about void main

You should be using int main
Back to top
View user's profile Send private message
DoomsDay
Grandmaster Cheater
Reputation: 0

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

PostPosted: Sun Mar 23, 2008 1:02 am    Post subject: Reply with quote

:P
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
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Sun Mar 23, 2008 1:28 am    Post subject: Reply with quote

x0r wrote:
slovach wrote:
Whatever compiler you're using is nice enough to complain about void main

You should be using int main

http://forum.cheatengine.org/viewtopic.php?p=2205775#2205775


Sure you can do it, but why go against the standard?
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 Mar 23, 2008 1:41 am    Post subject: Reply with quote

No worries, I'm always interested in more information to sponge up.

Though main has always returned int, if I remember right? (once upon a C story, there was no void)

e: whoops minor typo
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