this is a calculator which adds, subtracts, divides, multiplies, calculates areas and perimeters of a circle. although all appears fine to me, whenever i choose to add subtract or whatever, this is what happens. Example:
input:
2 + 3
output:
1972340 + 2348912 = blah blah...
aditionally, the management of pi number doesn't seem to work. It all stops when you click option 5 and 6, while it is supposed to ask you for a value to pi or to use the default one.
Code:
/*
// SimpleCal
//
// Created by Mario Nascimento on 2/26/12.
// <dimCode>
*/
#include <stdio.h>
#include "linech.h"
#include <stdlib.h>
double pi=3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491;
int sum();
int subtract();
int mult();
int divi();
int circa();
int circac();
int circp();
int circpc();
void exitt(void);
int main()
{
putchar('\n');
line(25,'*');
puts("\nWELCOME TO MARIOTUTORIALS\n");
line(25,'*');
int i = 0;
do
{
printf("\n\t[1.] \tSum");
printf("\n\t[2.] \tSubtraction");
printf("\n\t[3.] \tMultiplication");
printf("\n\t[4.] \tDivision");
printf("\n\t[5.] \tArea od Circle");
printf("\n\t[6.] \tPerimeter of Circle");
printf("\n\t[7.] \tEXIT");
printf("\nChoose a number:\n $ ");
scanf(" %d", &i);
fflush(stdin);
switch(i)
{
case 1 : sum(); break;
case 2 : subtract(); break;
case 3 : divi(); break;
case 4 : mult(); break;
case 5 : circa(); break;;
case 6 : circp(); break;
case 7 : exitt();
}
getchar();
}
while(i != 3);
getchar();
}
int sum()
{
double n1 = 0.0;
double n2 = 0.0;
printf("Insert two numbers (separated by + sign): ");
scanf("%d + %d", &n1, &n2);
printf("%d + %d = %d", n1, n2, (n1+n2));
getchar();
printf("\nPress Enter to Return to Main Menu");
getchar();
main(system("clear"));
}
int subtract()
{
double n1 = 0.0;
double n2 = 0.0;
printf("Insert two numbers (separated by - sign): ");
scanf("%d - %d", &n1, &n2);
printf("%d - %d = %d", n1, n2, (n1-n2));
getchar();
printf("\nPress Enter to Return to Main Menu");
getchar();
main(system("clear"));
}
int mult()
{
double n1 = 0.0;
double n2 = 0.0;
printf("Insert two numbers (separated by * sign): ");
scanf("%d * %d", &n1, &n2);
printf("%d * %d = %d", n1, n2, (n1*n2));
getchar();
printf("\nPress Enter to Return to Main Menu");
getchar();
main(system("clear"));
}
int divi()
{
double n1 = 0.0;
double n2 = 0.0;
printf("Insert two numbers (separated by / sign): ");
scanf("%d / %d", &n1, &n2);
printf("%d / %d = %d", n1, n2, (n1/n2));
getchar();
printf("\nPress Enter to Return to Main Menu");
getchar();
main(system("clear"));
}
int circa()
{
double j = 0.0;
printf("Enter a value for pi (enter 1 for default 500-digit) $ ");
scanf("%d",&j);
if(j==1)
{
circac();
}
else
pi == j;
circac();
}
circac()
{
double n1 = 0.0;
printf("Insert radius of circle: ");
scanf("%d", &n1);
printf("Area of Circle = %d",(pi * n1 * n1) );
getchar();
printf("\nPress Enter to Return to Main Menu");
getchar();
main(system("clear"));
}
int circp()
{
double k = 0.0;
printf("Enter a value for pi (enter 1 for default 500-digit) $ ");
scanf("ß%d",&k);
if(k==1)
{
circpc();
}
else
pi == k;
circpc();
}
circpc()
{
double n1 = 0.0;
printf("Insert radius of circle: ");
scanf("%d", &n1);
printf("Perimeter of Circle = %d",(pi * n1 * 2));
getchar();
printf("\nPress Enter to Return to Main Menu");
getchar();
main(system("clear"));
}
void exitt(void)
{
printf("\nPress [Enter] to exit");
}