NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

/*Program Name: Week 5Lab#6 Geometry Calculator.cpp
Programmer: Caleb Cohen
Date: 2/16/17
Version: 1.0
Description: Prompts user with a list of potential calculations, then calculates the one the user chooses based off of user input for the calculations.
*/
#include<iostream>
#include <cmath>

using namespace std;
int main()
{
int choice; //Defining variables
double radius; //Defining variables
double length; //Defining variables
double width; //Defining variables
double base; //Defining variables
double height; //Defining variables
double c_area; //Defining variables
double r_area; //Defining variables
double t_area; //Defining variables

cout << "Geometry Calculator" << endl; //Displaying menu
cout << "1. Calculate the Area of a Circle" << endl; //Displaying menu
cout << "2. Calculate the Area of a Rectangle." << endl; //Displaying menu
cout << "3. Calculate the Area of a Triangle." << endl; //Displaying menu
cout << "4. Quit" << endl; //Displaying menu

cin >> choice; //User selection
switch (choice) //Switch statement
{
case 1:
cout << "Please enter the radius of the circle: "; //Prompting user for radius
cin >> radius; //User enters radius
while (radius <= 0) //Loop to prevent radius from being below 0
{
cout << "Error! Number must be greater than zero!" << endl;
cout << "Please enter a new radius: ";
cin >> radius;
}
c_area = 3.14159 * radius; //Calculation for area
cout << "The area of the circle for the radius that you inputted is: " << c_area << endl; //Output for area of the circle
break;
case 2:
cout << "Please enter the length of the rectangle: "; //Prompting user for length
cin >> length; //User enters length
while (length <= 0) //Loop to prevent length from being below 0
{
cout << "Error! Number must be greater than zero!" << endl;
cout << "Please enter a new length: ";
cin >> length;
}
cout << "Please enter the width of the rectangle: "; //Prompting the user for width
cin >> width; //User enters width
while (width < 0) //Loop to prevent width from being below 0
{
cout << "Error! Number must be greater than zero!" << endl;
cout << "Please enter a new width: ";
cin >> width;
}
r_area = length * width; //Calculation for area
cout << "The area of the rectangle for the length and width that you inputted is: " << r_area << endl; //Output for area of the rectangle
break;
case 3:
cout << "Please enter the length of the triangle's base: "; //Prompting user for length of the base
cin >> base; //User enters length of the base
while (base < 0) //Loop to prevent length of the base from being below 0
{
cout << "Error! Number must be greater than zero!" << endl;
cout << "Please enter a new base: ";
cin >> base;
}
cout << "Please enter the height of the triangle: "; //Prompting user for the height
cin >> height; //User enters height
while (height < 0) //Loop to prevent height from being below 0
{
cout << "Error! Number must be greater than zero!" << endl;
cout << "Please enter a new height: ";
cin >> height;
}
t_area = height * base * 0.5; //Calculation for area
cout << "The area of the triangle for the height and base that you inputted is: " << t_area << endl; //Display for area
break;
case 4:
cout << "The program will now end.n"; //Ending program option 4
break;
default:
cout << "Error! Selection was not on the list!" << endl; //Anything other than the four options ends the program



}



return 0;
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.