mardi 19 septembre 2017

C++ program Calculator

Ok I am having a issue with defining a switch or calling it. Currently I have the variable I want to use as a char set to Null. That appears to stop the error I was getting. However now when I run the program in visual studio my case will not allow me to select any options from my menu. Can any one point me in the right direction?

#include <iostream>
#include<iomanip>
#include <cmath>
using namespace std;

int main()
{

    // declair Variables 

    const double PI = 3.14;

    char geocal = NULL; //use for switch 

    double area, height, baseOne, lenght, with, baseTwo, radius;

    double areaCircle;

    // begin program 
    cout << "Geomitry Calculator" << endl;
    cout << "*******************\n";
    cout
            << "Please select a number 1-6 to select a function.\nPlease DO NOT enter a negative number\n";

    cout << "1: Calculate the area of a circle " << endl;
    cout << "2: Calculate the area of a Rectangle" << endl;
    cout << "3: calculate the area of a Triangle" << endl;
    cout << "4: calculate the area of a Trapezoid" << endl;
    cout << "5: calculate the area of a Sphere" << endl;
    cout << "6: Exit.\n" << endl;

    switch (geocal)
    {

        case 1:

            cout << "Please enter the Radius of the circle " << endl;
            cin >> radius;

            if (radius <= 0)
            {
                cout
                        << "DO NOT enter negative numbers!\nPlease enter a new number\n";
            }

            else
            {

                areaCircle = PI * pow(radius, 2);
                cout << "the area is: " << areaCircle << endl;

            }
            break;
    }

    /* THIS IS A TEST if Statement. 
     //if statement used to catch if user enters a negative number. 
     cin >> area; 
     if (area < 0){
     cout << "Please DO NOT use negative numbers!"<<endl<<"Please select a number\n";
     cin>> area;
     } end of if 

     */

Aucun commentaire:

Enregistrer un commentaire