Hey, everyone, I'm a beginner to all types of programming, so I figured I'd place my first original (i.e. completely solved by me) up for comments and criticisms. I'm mainly looking on how to make it more streamlined, as I decided I might as well learn to make efficient code as I'm learning the language. Anyway, the following is a simple calculator program. Also, and I apologize in advance if this is a stupid question, but is there a command in c++ that is similar to the ClrHome command in Visual Basic. I haven't been able to find it in any of the books I'm using. Thanks.
Code:
/* ****************************************************************************
This program takes two numbers as input, asks the user to choose a operator,
then displays the result.
******************************************************************************/
#include <iostream>
using namespace std;
int main()
{
//First we declare the variables we will use for calculations
long double x, y;
long double result;
int z; //This is the value we will use for the operator
//Next we get our values from the user and display them to verify
cout << "Please enter a number: \n";
cin >> x;
cout << "Please enter a second number: \n";
cin >> y;
cout << "\n" << "Your numbers are " << x << " and " << y << "\n";
cout << "\n";
//Next we display the possible operators
cout << "(1) Add \n";
cout << "(2) Subtract \n";
cout << "(3) Multiply \n";
cout << "(4) Divide \n";
cin >> z;
cout << "\n";
//Now we do the calculations
switch ( z )
{
case 1:
result = x + y;
break;
case 2:
result = x - y;
break;
case 3:
result = x * y;
break;
case 4:
result = x / y;
break;
default:
cout<<"Error, bad input, quitting\n";
break;
}
cout << "The result is " << result << "\n";
return 0;
}