How do I get this program to work?

I am still new to C++
I am writing a code that will find the area of a pyramid
Could you please help me understand why this program is not working?

#include <iostream>
#include <string>

using namespace std;

int main ()

{


//User inputs Pyramid's area.
cout <<" input pyramid's area." << endl;
cin >> a;

//User inputs Pyramid's height.
cout <<"input pyramid's height.";
cin >> h;

//declares a, h.
float int = a
float int = h
float int = v
//calculates the Pyramid's volume.

cout << fixed << setprecision (2) << v = (a*h)/3 << endl;

//output to screen

cout<< "The volume of the cone is" << v << endl;

system("PAUSE");

return 0;
}
Last edited on
Hi, it seems that you're confused over variable types and/or declaration. See further comments in the source below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
//#include <string> You aren't using this header
#include <iomanip> // You'll need this header for setprecision
 
using namespace std;
 
int main ()
{
// Declare your variables before using them
// Also, granted them more meaningful names

  float area;
  float height;
  float volume;

  cout << "input pyramid's area: " << endl;
  cin >> area;
 
  cout << "input pyramid's height: " << endl;
  cin >> height;
 
  volume = (area * height) / 3;
 
  cout << "The volume of the cone is " << fixed << setprecision (2) << volume << endl;
  return 0;
}
Last edited on
Yeah i kind of am. tried to get help from some friends but most dont know c++
What is the difference?
so in language like bash you can have lots of flexability eith variables but in c++ you have to declare all of your variables with their data types (there are six)
Thanks so much guys :)
very much appreciate your input
so i retried the code again its not working now
Am I missing something else?
Show us the code you have now.
remember to use more meaningfull names for variables declaration.
#include <iostream>


#include <iomanip>
using namespace std;

int main ()
{

float area;
float height;
float volume;

cout << "input pyramid's area: " << endl;
cin >> area;

cout << "input pyramid's height: " << endl;
cin >> height;

volume = (area * height) / 3;

cout << "The volume of the cone is " << fixed << setprecision (2) << volume << endl;
return 0;
}

This is my code that doesnt work
its cout.fixed abnd cout.setprecision(2) : they are data members of the ostream class and traditionally accessed with cout but you can use cerr or wcerr or make your own
Topic archived. No new replies allowed.