|
From: Dondolo M. <MDo...@OL...> - 2003-04-03 10:03:15
|
Hi all.
I am getting there with c++. there is one question I would like to ask. I
was experimenting with a simple calculator program that I wrote. What the
program does is it prompts you to enter the first number, then the second
number. The next step , you are prompted to choose what you wanna do with
the numbers eg Multiply, add...
What I want is when the user selects his choice, the answer must be
displayed on a clean "page" and not show all the other previous info ...ie,
the numbers being calculated or the menu to select from.
//-----------
#include<iostream.h>
#include<stdlib.h>
//A funcion that adds two numbers
float Add(float x, float y)
{
return (x+y);
}
//-----------------------------
float Multiply(float x, float y)
{
return (x*y);
}
//----------------------------
float Minus(float x, float y)
{
return (x-y);
}
//--------------------
float Divide( float x, float y)
{
return (x/y);
}
//---------
//--------
main()// main function
{
float a,b,c;
int Ans;
cout<<"Enter first number : ";
cin>>a;
cout<<"...and the second number : ";
cin>>b;
cout<<"\n";
cout<< "\t\t\t 1)ADD\n"
"\t\t\t 2)DIVIDE\n"
"\t\t\t 3)MULTIPLY\n"
"\t\t\t 4)SUBTRACT\n";
cout<<"_";cin>>Ans;
if (Ans==1)
{
c=Add(a,b);
cout<<c;
}
if (Ans==2)
{
c= Divide(a,b);
cout<<c;
}
if(Ans==3)
{
c=Multiply(a,b);
cout<<c;
}
if(Ans==4)
{
c= Minus(a,b);
cout<<c;
}
system("PAUSE");
}
Mpho Dondolo
Support Analyst
Computer Sciences Corp. (CSC)
Tel: +27 21 503 0059
Fax: +27 21 509 5619
Cell: +27 84 337 1468
mdo...@cs...
mdo...@ol...
|