mercredi 19 octobre 2016

Looping the formula for the area of a rectangle

I'm at my wits end on this assignment. I need the user to be able to do a few things.

  1. Enter which shape they want to hold sheep (by pushing 1 or 2).
  2. Enter how many corrals they want; 3 being the max.
  3. Output the area and number of sheep for each corral.

The circle formula works, but the rectangle pauses after you enter the number of corrals. The output for the rectangle section does not show up at all. I've tried a combination of using while, switch, case, and else, and I can't get it to work.

How do I get the formula section to appear, and how do I use "while" to loop the rectangle formula 3 times? Any help?

// ConsoleApplication16.cpp : Defines the entry point for the console    application.
//

#include "stdafx.h"
#include <iostream>
#include <cstdio>
#include <cmath>
#include <iomanip>

using namespace std; 

int main()
{
const double pie = 3.141592;
double r;
double area = 0;
double length;
double width;
int shape;
double sheep = 2.54;
int corral;

cout << " Which shape do you want? " << endl;
cout << " 1. Circle.   2. Rectangle. ";
cin >> shape;
cout << " How many corrals do you want? " << endl;
cin >> corral;

while (corral <= 3)

    if (shape == 1)
    {
        cout << "Input radius. " << endl;
        cin >> r;
        cout << fixed << setprecision(2);
        area = pie * pow(r, r);
        cout << endl;

        cout << " Here's the area. << " endl;
        cout << area << endl;
        cout << fixed << setprecision(1) << "Number of sheep " << area / sheep << endl;
    }


else (shape = 2);
        {   
        cout << "Enter lenght and width. " << endl;
        cin >> length;
        cin >> width;
        area = length * width;

        cout << "Here's the area. " << endl;
        cout << area << endl;
        cout << "Number of sheep" << endl;
        cout << fixed << setprecision(2);
        cout << area / sheep;
        }




return 0;

}

Aucun commentaire:

Enregistrer un commentaire