Thread: 3-dimensional solid program

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    21

    Question 3-dimensional solid program

    Hello,
    I am working on a program where the user enters the 3 dimensions of a solid (any solid) and the program calculates the volume of the figure!
    I have tried it and i have a list of errors, but i can't seem to figure out how to fix them.
    I was hoping that maybe someone here could give me a hand or whatever and help me out here. Below is my code, and below that is my error report!
    Thanks a bunch, i sure hope someone here will be able to help me out!

    Here is my program code:

    Code:
    //Description: This program asks for the 3 dimensions of a solid to calculate the volume of the figure.
    
    #include <iostream>
    #include <cmath>
    #include <string>
    
    int main()
    {
      int menu;
      double cubeside;
      double basel;
      double sqph;
      double radi;
      double cylh;
      double radi2;
      double coneh;
      double radi3;
      double edge;
      double hexh;
      string response;
    
      do
      {
    
    cout << "\fWelcome to the Math Cheater 3000. All I need is for you" << endl;
    cout << "to pick the 3D object and I will calculate the volume of it." << endl;
    cout << "Sounds pretty easy. Can you do it? Just try. The numbers" << endl;
    cout << "corresponds with the 3D figure." << endl;
    
    // Pick a number on the menu
    
      cout << "\n1. Cube \n2. Square Pyramid \n3. Cylinder \n4. Cone \n5. Sphere \n6. Hexagonal Prism" << endl;
      cout << "Pick a number: ";
      cin >> menu;
    
    // Puts up an error that they need to pick a number on the menu and to do it again.
    
      if(menu != 1 && menu != 2 && menu != 3 && menu != 4 && menu != 5 && menu != 6)
      {
       cout << "Pick a number on the menu: ";
       cin >> menu;
      }
    
    // Each menu asks for the important formula points needed for the it to be solved.
    
       if(menu == 1)
       {
        cout << "Pick side length of choosen cube: ";
        cin >> cubeside;
        cout << "The volume of cube is: "<< pow(cubeside,3) << endl;
       }
       if(menu == 2)
       {
        cout << "Pick base length and height." << endl;
        cout << "Base length: ";
        cin >> basel;
        cout << "Height: ";
        cin >> sqph;
        cout << "The volume of square pyramid is: "<< (basel*basel)*(sqph)/3
             << endl;
       }
       if(menu == 3)
       {
        cout << "Pick radius and height of cylinder." << endl;
        cout << "Radius: ";
        cin >> radi;
        cout << "Height: ";
        cin >> cylh;
        cout << "The volume of cylinder is: "<< (3.14 * pow(radi,2)) * cylh << endl;
       }
       if(menu == 4)
       {
        cout << "Pick radius and height of cone." << endl;
        cout << "Radius: ";
        cin >> radi2;
        cout << "Height: ";
        cin >> coneh;
        cout << "The volume of cone is: "<< (3.14 * pow(radi2,2)) * coneh << endl;
       }
       if(menu == 5)
       {
        cout << "Pick radius of sphere." << endl;
        cout << "Radius: ";
        cin >> radi3;
        cout << "The volume of sphere is: "<< (3.14 * pow(radi3,3)) * (4/3)<< endl;
       }
       if(menu == 6)
     {
        cout << "Pick edge length and height." << endl;
        cout << "Edge length: ";
        cin >> edge;
        cout << "Height: ";
        cin >> hexh;
        cout << "The volume of the hexagonal prism is: "<< (.5*(edge * 6))*((edge/2)*(1.732))*(hexh)
             << endl;
       }
    
    // Asks if they want to do it again.
    
        cout << "Again?: ";
        cin >> response;
    
    
      } while (response == "y" || response == "Y");
    
      return 0;
    }
    And my error report:
    Code:
    1project.cpp: In function âint main()â:
    1project.cpp:23: error: âstringâ was not declared in this scope
    1project.cpp:23: error: expected `;' before âresponseâ
    1project.cpp:28: error: âcoutâ was not declared in this scope
    1project.cpp:28: error: âendlâ was not declared in this scope
    1project.cpp:37: error: âcinâ was not declared in this scope
    1project.cpp:104: error: âresponseâ was not declared in this scope
    1project.cpp:107: error: âresponseâ was not declared in this scope
    It would be great if you could let me know if you find it, but i iwll keep on working it out.
    Thank you all for this great website and your help!!!

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    These are the same errors as the last time you posted, and they have the same resolution.

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    21
    uh, but what would that be?
    That's what I am wanting to find out.

  4. #4
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    This forum has a search feature.

    Click on your name and you can see all the posts you have made.

    Soma

  5. #5
    Registered User
    Join Date
    Nov 2008
    Posts
    21
    I apologize, I am a bit confused right now.
    Do I have to go somewhere to find the answer or suggestion to my problem, or does someone just post it here if they notice it?
    Thanks for all of your patience with me.

  6. #6
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    http://cboard.cprogramming.com/searc...archid=1445685

    Just click your name, and "Find all posts by thekautz". How difficult is that?

  7. #7
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    This response was given to you in your last thread:
    Quote Originally Posted by tabstop View Post
    So you don't have such things as string, cout, cin, or endl. But there is std::string, std::cout, std::cin, and std::endl. (Perhaps you wanted a using declaration.)
    In other words, you want a "using namespace std;" line after your includes.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  8. #8
    Registered User
    Join Date
    Nov 2008
    Posts
    21

    Thanks!

    Ok, thank you all very much, sorry for the trouble!
    I got it to work and it is great!
    Thanks once again!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  2. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM