Welcome to Dream.In.Code
Become a C++ Expert!

Join 136,941 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,870 people online right now. Registration is fast and FREE... Join Now!




please need some help using c

 
Reply to this topicStart new topic

please need some help using c, just need to make it in one statement, and also add a clear

ladiesman
15 Mar, 2008 - 09:00 PM
Post #1

New D.I.C Head
*

Joined: 9 Feb, 2008
Posts: 35

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.



cpp
 
#include<stdio.h>
#include<math.h>
int main()
{
int c;
float a, b;
char d;
printf("Enter the first number");
scanf("%f",&a);
getchar();
printf("Enter the function:");
scanf("%c",&d);
getchar();
printf("Enter the second number");
scanf("%f",&b);
getchar();
while (0==0)
{
if (d=='*')
{
a=a*b;
}
if (d=='/')
{
a=a/b;
}
if (d=='+')
{
a=a+b;
}
if (d=='-')
{
a=a-b;
}
switch ©
{
case 'Q':
case 'q': return;

}
printf("value is %f ",a);
getchar();
return;
}
}

how can i make my calculator read the first number the function and the second number in one statement. then print the answer.
User is offlineProfile CardPM
+Quote Post

born2c0de
RE: Please Need Some Help Using C
16 Mar, 2008 - 05:20 AM
Post #2

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 3,912



Thanked: 34 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
QUOTE
i need to know how to clear screen

Use the clrscr() function from the conio.h header file.

Remember that functions in conio.h work only on Windows and cannot be ported to other operating systems such as Linux.
But since you're asked to use getch() (also a non-standard function), you needn't worry about maintaining portability.
User is online!Profile CardPM
+Quote Post

Stepler
RE: Please Need Some Help Using C
16 Mar, 2008 - 06:09 AM
Post #3

New D.I.C Head
*

Joined: 4 Mar, 2008
Posts: 27



Thanked: 2 times
My Contributions
QUOTE

how can i make my calculator read the first number the function and the second number in one statement. then print the answer.

I modified your code.
CODE

#include<stdio.h>
#include<math.h>
#include<conio.h>
#include<stdlib.h>
int main()
{
int c;
int a, b;
char d;
pov:system("cls");
printf("Enter the first number\n");
a=getch()-48;
system("cls");
printf("Enter the function:\n");
d=getch();
system("cls");
printf("Enter the second number\n");
b=getch()-48;
system("cls");
while (0==0)
{
if (d=='*')
{
a=a*b;
}
if (d=='/')
{
a=a/b;
}
if (d=='+')
{
a=a+b;
}
if (d=='-')
{
a=a-b;
}
printf("value is %d \n",a);
printf("Press 'q' to quit, or press other key to repeat data input\n");
c=getch();
if((c=='q')||(c=='Q')) return;
goto pov;
}
}

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/3/08 10:57PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month