Our assignment is to write a program that calculates the volume of three geometric shapes, the program should ask for a shape and the three shapes we are to use is a dumbell, axle, spear. And he gives us the formulas for volume and how to find it. I know that I need to write a if /else statement and so if its dumbell to calculate the volume using the given formulas and if it is not to go to next if statement.

so far I have:

int main()
{
    time_t t;
    time(&t);

    yl;
    cls;
    
    char shape, dumbell, axle, spear;
    double radius, radius2, width, length, heigth, volume;
    double pi = 3.14159;
    
    cout << "Give me a Geometric Shape " << endl;
    cin >> shape;
    
    if (shape == dumbell){
    cout << "What is the Radius of the Sphere? " << endl;
    cin >> radius;
    cout << "What is the Radius and Length of the Rod? " << endl;
    cin >> radius2 >> length;
    cout << fixed << showpoint << setprecision (3);
}
   else 
    if(shape == axle)
    cout << "What is the Radius of the Rod? " << endl;
   
   else 
    if(shape == spear)
    cout << "What is the Radius of the Cone? " << endl;


       
    frz;
    return 0;
} // end of main function

and so far when i run the program it says the firs question "give me a geometric shape?,, but i type dumbell, and it just skips to "What is the Radius and Length of the rod" and then quits the program. but I want to stop and wait for dumbell adn then go to the next question and wait for an answer.
\
Any help would be greatly appreciated.

Recommended Answers

All 3 Replies

> char shape, dumbell, axle, spear;
Make this std::string shape; Plus, you don't need those other 3 anymore than you need a variable called banana in order to hold the string "banana". std::string fruit = "banana"; // pedants feel free to point out that banana is a herb Having done that, you can proceed with if (shape == "dumbell" ) and so forth.

Read this for posting code in future.
http://www.daniweb.com/techtalkforums/announcement8-3.html

int main()
{
	time_t t;
	time(&t);

What is this for?

yl;
	cls;

And what is that?

frz;

And what is that?

Member Avatar for iamthwee
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

int main()
{
   time_t t;
   time ( &t );

   //yl;
   //cls;

   string shape, dumbell, axle, spear;
   double radius, radius2, width, length, heigth, volume;
   double pi = 3.14159;

   cout << "Give me a Geometric Shape " << endl;
   cin >> shape;

   if ( shape == "dumbell" )
   {
      cout << "What is the Radius of the Sphere? " << endl;
      cin >> radius;
      cout << "What is the Radius and Length of the Rod? " << endl;
      cin >> radius2 >> length;
      cout << fixed << showpoint << setprecision ( 3 );
   }
   else
      if ( shape == "axle" )
         cout << "What is the Radius of the Rod? " << endl;

      else
         if ( shape == "spear" )
            cout << "What is the Radius of the Cone? " << endl;

   //frz;
   cin.get();
   return 0;
} // end of main function

Repetition I know, but have a look at the parts in red.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.