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);
}

i need to know how to clear screen and also how to get the numeric keys without pressing enter.

Both of those questions are answered in your post. You might want to reread it and look up the things suggested.

And while you're at it. look this up, too.

Your post says that your assignment requires you to enter an expression the same way you would as if you were typing it into a calculator. i.e. 6 + 4 [enter key]. In your program, you require the user to type a letter to indicate what operation they want to perform.

this is a tough problem. i actually tried to do this last night, and i could not get it to work right.

getch() from the <curses.h> library, did not work as advertised for me.

and im using the gcc compiler.

obviously the getchar( ) function requires an <ENTER> before reading the input buffer, so that won't work either.

i know i did something like this maybe 5 years ago. perhaps I was using the <conio.h> windows library, which wouldn't be helpful for someone on *nix, using <curses.h>

i mean, not that this is really a representative "real world" problem, but it's a head scratcher.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.