I have built a code for class and it does nto work. I do not understand why. Can someonne look over the code and give me some explination to why it does not build.
///*specification: Raymond Henry Sr Lab2 exercise 2
//My Calculator
#include <iostream>
using namespace std;
int firstNum = 0;
int secondNum = 0;
int operator = 0;
int answer = 0;
int main()
{
cout << "Welcome to My Calculator: "<< endl;
cout << "Please Enter the first number followed by the second number followed by the operation you would like to accomplish: " << endl;
cout << "Enter First number: " << endl;
cin >> firstNum << endl;
cout << "Enter Second number: " << endl;
cin >> secondNum << endl;
cout << "Select an operation: " << endl;
There are a few bugs in your program, read the error messages you get and you will be able to find them. Few notes to point you in the right direction:
-you cant use reserved key-words as name for variables
-i dont know "enum", but your program doesnt recognize it either. Maybe you have to include another library for that?
-For every open-bracket "{" you use you need only one close-bracket "}"
-you cant use the inputstream for any output (including new lines)
Well one of my classmates says my code should look like this but changed to handle the calculations for a calculator. I am so confused. This code produces calculations for a circle. Our code is supposed to do various calculations. The part where I am having the trouble is converting the perform calculations part.
//specification: this program accepts a the radius of a circle and computes a the diameter
//circumference and Area and displays whichever value the user selects from a menu.
//This is a demonstration program to highlight the core concepts of this weeks lecture
#include <iostream>
int main (){
//ask the user for a circle's radius
double userRadius = 0;
cout << endl << "Welcome to the Circle Calculator!\n";
cout << endl << "Enter a Radius: ";
cin >> userRadius;
cout << endl << endl;
//ask the user for his desired calculation
int usersChoice = 0;
cout << "Choose a Calculation Option:\n\n";
cout << "1 - Circumference\n";
cout << "2 - Diameter\n";
cout << "3 - Area\n";
cout << "0 - Exit\n";
cout << "Enter a number: ";
cin >> usersChoice;
if (usersChoice < 0 || usersChoice > 3){
cout << endl << "Invalid choice - program terminated\n\n";
}
else {
case circle::Circum:
cout << endl
<< "A circle with a radius of "
<< myCircle.radius
<< " has a Circumference of "
<< myCircle.circum << "\n\n"; break;
case circle::Diameter:
cout << endl
<< "A circle with a radius of "
<< myCircle.radius
<< " has a diameter of "
<< myCircle.diameter << "\n\n"; break;
case circle::Area:
cout << endl
<< "A circle with a radius of "
<< myCircle.radius
<< " has an area of "
<< myCircle.area
<< "\n\n"; break;
default:
cout << endl << "Not a valid choose!\n\n";
}
> In the first code you posted, you are using operator as variable name, as enum and it is a keyword. This will be very confusing for your compiler
> You are using many times things like cin >> firstNum << endl;
but it should be
1 2
cin >> firstNum;
cout << endl;
> In the enumerator the value Modulus Division contains a space, change it to Modulus_Division (why did you declare this enum if you didn't use it?)
> At the end you are missing a semicolon
1 2
else
{ cout << "Error: "; }
> You have to delete all the extra };
> I suggest you to use a char to get the operator, not an int and to use a float or a double for the number used in the calculations in order to have more precise results on division
Bazzy, we have to make the code similar to the second one I posted and it has to calculate and give the answer for the calculation. They require us to have a enumerator and switch statement. I am so confused. I need to eliminate the junk for the circle and add the mathmatical equations fo rthis program to perform the math functions.