3 dimensional figure volume

This is a discussion on 3 dimensional figure volume within the C++ Programming forums, part of the General Programming Boards category; Here is the code for my program: It is supposed to ask for 3 dimensions of a solid to find ...

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

    Question 3 dimensional figure volume

    Here is the code for my program:
    It is supposed to ask for 3 dimensions of a solid to find the volume of the figure.

    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 
              to pick the 3D object and I will calculate the volume of it. 
    	  Sounds pretty easy. Can you do it? Just try. The numbers 
    	  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;
    }
    Here is my error report:
    Code:
    1project.cpp:28:11: warning: missing terminating " character
    1project.cpp:28: error: missing terminating " character
    1project.cpp:29:23: error: invalid suffix "D" on integer constant
    1project.cpp:31:25: error: invalid suffix "D" on integer constant
    1project.cpp:31:35: warning: missing terminating " character
    1project.cpp:31: error: missing terminating " character
    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:29: error: ‚to‚ was not declared in this scope
    1project.cpp:29: error: expected `;' before ‚pick‚
    1project.cpp:37: error: ‚cin‚ was not declared in this scope
    1project.cpp:53: error: ‚endl‚ was not declared in this scope
    1project.cpp:57: error: ‚endl‚ was not declared in this scope
    1project.cpp:67: error: ‚endl‚ was not declared in this scope
    1project.cpp:76: error: ‚endl‚ was not declared in this scope
    1project.cpp:85: error: ‚endl‚ was not declared in this scope
    1project.cpp:92: error: ‚endl‚ 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 someone could help me out with my errors, and I am still trying to figure them out.
    Thanks!

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    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.)

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Fix your string on line 11 first. In case you don't know, thats this one:

    Code:
      cout << "\fWelcome to the Math Cheater 3000. All I need is for you 
              to pick the 3D object and I will calculate the volume of it. 
    	  Sounds pretty easy. Can you do it? Just try. The numbers 
    	  corresponds with the 3D figure." << endl;
    If you have a long line like that, you have to end EACH line with a ", the compiler doesn't like it when you put a newline in the middle of a string.

    And in C and C++ it is perfectly valid to write a string as "abc" "def" - it is the same as "abcdef", and the space can be any number of any of the whitespace characters (space, newline, tab, form-feed (CTRL-L) [and probably some others]) that are acceptable elsewhere in a statement of C or C++.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Volume of a Cone Equation always equals 0
    By Devolution in forum C Programming
    Replies: 11
    Last Post: 01-28-2009, 02:13 AM
  2. Multi dimensional array
    By $l4xklynx in forum C Programming
    Replies: 7
    Last Post: 01-03-2009, 02:56 AM
  3. Two dimensional array
    By George2 in forum C Programming
    Replies: 3
    Last Post: 11-10-2007, 04:27 AM
  4. Help! Right Math, Wrong Output
    By verd in forum C Programming
    Replies: 12
    Last Post: 03-15-2005, 06:49 PM
  5. Have you ever had a four dimensional experience
    By Silvercord in forum A Brief History of Cprogramming.com
    Replies: 35
    Last Post: 08-18-2003, 06:13 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21