 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Sat Mar 22, 2008 4:06 am Post subject: [C]A simple calc |
|
|
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 |
|
 |
Estx Expert Cheater
Reputation: 0
Joined: 04 Mar 2008 Posts: 172
|
Posted: Sat Mar 22, 2008 5:02 am Post subject: |
|
|
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
|
|
| Back to top |
|
 |
Anden100 Grandmaster Cheater
Reputation: 0
Joined: 20 Apr 2007 Posts: 668
|
Posted: Sat Mar 22, 2008 5:24 am Post subject: Re: [C]A simple calc |
|
|
| 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 |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sat Mar 22, 2008 9:40 am Post subject: |
|
|
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 |
|
 |
spectrum Expert Cheater
Reputation: 0
Joined: 27 Mar 2007 Posts: 143
|
Posted: Sat Mar 22, 2008 10:22 am Post subject: |
|
|
It gives me an error, it says:"main must return int".
_________________
C++ {||||||||||}
ASM {||||||||||} |
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Sat Mar 22, 2008 11:34 am Post subject: Re: [C]A simple calc |
|
|
| 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 |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Sat Mar 22, 2008 2:06 pm Post subject: |
|
|
| 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 |
|
 |
DoomsDay Grandmaster Cheater
Reputation: 0
Joined: 06 Jan 2007 Posts: 768 Location: %HomePath%
|
Posted: Sun Mar 23, 2008 1:02 am Post subject: |
|
|
: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 |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Sun Mar 23, 2008 1:28 am Post subject: |
|
|
Sure you can do it, but why go against the standard?
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Sun Mar 23, 2008 1:41 am Post subject: |
|
|
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 |
|
 |
|
|
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
|
|