Write functions to:
void clearscreen(void); /* Clears the screen for update, hint call system("clear") */
float calc(float num1,float num2,char operator); /* calculate the result of num1 operator num2 */
any other functions which you deem necessary.
Write a main program which will display a title line centered at the top of the screen
like: Fred's Calculator
and basically sit and wait for input from the keyboard.
Your program will respond to the numeric keys and form up a number on the result line, below the title (refreshing on every keypress)
Your program will also respond to the basic function keys... + - * / taking the previously entered value and then performing the action on the next entered value... just like your handheld calculator.
The enter key will replace the = key in the program.
The q key will shut down the program cleanly.
Make certain your program is well documented and executes correctly, make certain it accepts all keyboard input but then responds only to the ones listed above and ignores the rest. Use getch() to pull in input from the keyboard on a character by character basis.
heres my program to far:
i need to know how to clear screen and also how to get the numeric keys without pressing enter.
#include<math.h>
#include<stdio.h>
#include<curses.h>
int main(void)
{
float num1,num2,answer,i;
char c;
printf("\t\t\t""kieran's calculator!!!\n");
printf("\t\t\t\t""%f\n",answer);
printf("A Adition\n");
printf("S Subtraction\n");
printf("M Multiplication\n");
printf("D Division\n");
printf("R Squareroot\n");
printf("P Percentage\n");
printf("Q Quit\n");
c=getchar();
switch (c)
{
case 'A':
case 'a': addition:
printf("Enter two numbers:\n");
scanf("%f",&num1);
scanf("%f",&num2);
answer=num1+num2;
break;
case 'S':
case 's': subtraction:
printf("Enter two numbers to subtract:\n");
scanf("%f",&num1);
scanf("%f",&num2);
if (num1>num2) {
answer=num1-num2;
}
else if (num1<num2){
answer=num2-num1;
}
break;
case 'M':
case 'm': multiply:
printf("Enter two numbers to multiply:\n");
scanf("%f",&num1);
scanf("%f",&num2);
answer=num1*num2;
break;
case 'D':
case 'd': division:
printf("Enter 2 numbers to be divided:\n");
scanf("%f",&num1);
scanf("%f",&num2);
if (num1>num2) {
answer=num1/num2;
}
else if (num1<num2){
answer=num2/num1;
}
break;
case 'R':
case 'r': squareroot:
printf("enter number to be square rooted:\n");
scanf("%f",&num1);
answer = sqrt(num1);
break;
case 'P':
case 'p': percent:
printf("Enter first number to be the percent and the second number to be\n");
scanf("%f",&num1);
scanf("%f",&num2);
answer = (num1*num2)/100;
break;
case 'Q':
case 'q': return;
}
printf("%f\n",answer);
}