|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming | |
Basic C++ program, need help
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | |||||||||||||
|
Folding Fanatic
![]() |
Alright, so I just tried writing my first program on how to find the volume of a cylinder.
Code:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
(
double r, he;
cout<<"What is the radius of the cylinder?";
cin>>r;
cout<<"What is the height of the cylinder?";
cin>>he;
p = 3.14159
v = p * r * r * he;
sae = 2 * p * r * r;
sas = 2 * p * r * he;
sac = (2 * p * r * r) + (2 * p * r * he);
cout<<"/n Radius"<< r
cout<<"/n Height"<< he
cout<<"/n Surface Area of the Ends"<< sae
cout<<"/n Surface Area of the Sides"<< sas
cout<<"/n Surface Area of the Cylinder"<< sac
cout<<"/n Volume of Cylinder"<< v;
system ("pause");
return 0;
)
Last edited by tofunater : 09-02-09 at 09:10 PM |
|||||||||||||
|
|
|
|
|
#2 (permalink) | |||||||||||||
|
*cough* Stock *cough*
![]() |
when u ask for the height, ur variable is h, but in the rest of the program it is "he", u need to change the h to he.
__________________
|
|||||||||||||
|
|
|
|
|
#3 (permalink) | |||||||||||||
|
*cough* Stock *cough*
![]() |
also, for you second cout, you used >> instead of <<.
__________________
|
|||||||||||||
|
|
|
|
|
#4 (permalink) | |||||||||||||
|
Folding Fanatic
![]() |
changed, and I'm still receiving the same error. Thanks for the catch though. +
|
|||||||||||||
|
|
|
|
|
#5 (permalink) | ||||||||||||||
|
*cough* Stock *cough*
![]() |
Quote:
#include <iostream> #include <iomanip> using namespace std; int main() { double r, he; cout<<"What is the radius of the cylinder?"; cin>>r; cout<<"What is the height of the cylinder?"; cin>>he; p = 3.14159 v = p * r * r * he; sae = 2 * p * r * r; sas = 2 * p * r * he; sac = (2 * p * r * r) + (2 * p * r * he); cout<<"/n Radius"<< r; cout<<"/n Height"<< he; cout<<"/n Surface Area of the Ends"<< sae; cout<<"/n Surface Area of the Sides"<< sas; cout<<"/n Surface Area of the Cylinder"<< sac; cout<<"/n Volume of Cylinder"<< v; system ("pause"); return 0; } You missed a few semi colons and used () instead of {}
Last edited by muels7 : 09-02-09 at 09:13 PM |
||||||||||||||
|
|
|
|
|
#6 (permalink) | ||||||||||||
|
Folding Fanatic
![]() |
p = 3.14159 you area missing the ;
__________________
So you think you're ready to fold...well, then look here:
|
||||||||||||
|
|
|
|
|
#7 (permalink) | |||||||||||
|
PC Gamer
|
You need to classify p and v as doubles first. Same goes for sae, sas, sac.
|
|||||||||||
|
|
|
|
|
#8 (permalink) | ||||||||||||
|
Graphics Card Aficionado
![]() |
You can use the "pow" function to raise something to the power of a number. It makes it easier than putting R * R
Also the second cout statement has the "<<" facing the wrong way. I see you fixed it This. I didn't catch this on my first time round. p is not set as a variable which means the computer doesn't know where to assign the number to.
__________________
Steam/TF2 Name: [OCN]Rubbish
Last edited by Drift0r : 09-02-09 at 09:14 PM |
||||||||||||
|
|
|
|
|
#9 (permalink) | |||||||||||||
|
*cough* Stock *cough*
![]() |
this, i missed it as well.
__________________
|
|||||||||||||
|
|
|
|
|
#10 (permalink) | |||||||||||||
|
Folding Fanatic
![]() |
#include <iostream>
#include <iomanip> using namespace std; int main() { double r, he; cout<<"What is the radius of the cylinder?"; cin>>r; cout<<"What is the height of the cylinder?"; cin>>he; double p = 3.14159; v = p * r * r * he; sae = 2 * p * r * r; sas = 2 * p * r * he; sac = (2 * p * r * r) + (2 * p * r * he); cout<<"/n Radius"<< r cout<<"/n Height"<< he cout<<"/n Surface Area of the Ends"<< sae; cout<<"/n Surface Area of the Sides"<< sas; cout<<"/n Surface Area of the Cylinder"<< sac; cout<<"/n Volume of Cylinder"<< v; system ("pause"); return 0; } I have this now, and I made it until line 12, where it says that v is undeclared.
|
|||||||||||||
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|