Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming

Reply
 
LinkBack Thread Tools
Old 09-02-09   #1 (permalink)
Folding Fanatic
 
tofunater's Avatar
 
intel nvidia

Join Date: Sep 2006
Location: Dekalb, IL
Posts: 2,479

Rep: 203 tofunater is acknowledged by manytofunater is acknowledged by manytofunater is acknowledged by many
Unique Rep: 176
Folding Team Rank: 278
Trader Rating: 24
Default Basic C++ program, need help

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;
)
I'm struggling to get it to compile though because of an error on the sixth line. My teacher's notes are terrible and I won't have a reference book until after this weekend. So any help would be much appreciated.
__________________

Quote:
Originally Posted by iandh View Post
People like this know deep down inside that they are absolutely worthless, so they must constantly come up with new ways to give themselves worth, otherwise they may be tempted to end it all one day by OD'ing on Care-Bears marathons.

System: Hedonism, Stanford Style
CPU
i7 920 D0
Motherboard
Asus P6T6 WS revolution
Memory
6 gigs G-skill
Graphics Card
Tri-sli 260's
Hard Drive
620aaks
Sound Card
on board
Power Supply
Zalman 850
Case
hardwood techstation(soon)
CPU cooling
GTZ/bix 360/355 (soon)
GPU cooling
water (soon)
OS
Vista 64
Monitor
22" Samsung 225BW
Overclock.net - 2009 Chimp Challenge Champions

Last edited by tofunater : 09-02-09 at 09:10 PM
tofunater is offline I fold for Overclock.net   Reply With Quote
Old 09-02-09   #2 (permalink)
*cough* Stock *cough*
 
muels7's Avatar
 
intel nvidia

Join Date: Jun 2009
Location: Chicago, Illinois
Posts: 650

Rep: 36 muels7 is acknowledged by some
Unique Rep: 34
Folding Team Rank: 1009
Trader Rating: 0
Default

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.
__________________
System: Waste of money..... but who cares!!
CPU
Core 2 Quad Q9650
Motherboard
Gigabyte GA-EP45-UD3P
Memory
8GB G.Skill PC-8500
Graphics Card
EVGA Nvidia 9800GTX+
Hard Drive
2x1TB Seagate Barracuda 7200.12
Sound Card
Creative X-Fi Titanium
Power Supply
Raidmax RX-730SS
Case
APEVIA X-TELSTAR-BK
CPU cooling
Xigmatek Dark Knight
GPU cooling
Stock
OS
Windows 7 Pro x64
Monitor
Asus VH236H
muels7 is offline I fold for Overclock.net   Reply With Quote
Old 09-02-09   #3 (permalink)
*cough* Stock *cough*
 
muels7's Avatar
 
intel nvidia

Join Date: Jun 2009
Location: Chicago, Illinois
Posts: 650

Rep: 36 muels7 is acknowledged by some
Unique Rep: 34
Folding Team Rank: 1009
Trader Rating: 0
Default

also, for you second cout, you used >> instead of <<.
__________________
System: Waste of money..... but who cares!!
CPU
Core 2 Quad Q9650
Motherboard
Gigabyte GA-EP45-UD3P
Memory
8GB G.Skill PC-8500
Graphics Card
EVGA Nvidia 9800GTX+
Hard Drive
2x1TB Seagate Barracuda 7200.12
Sound Card
Creative X-Fi Titanium
Power Supply
Raidmax RX-730SS
Case
APEVIA X-TELSTAR-BK
CPU cooling
Xigmatek Dark Knight
GPU cooling
Stock
OS
Windows 7 Pro x64
Monitor
Asus VH236H
muels7 is offline I fold for Overclock.net   Reply With Quote
Old 09-02-09   #4 (permalink)
Folding Fanatic
 
tofunater's Avatar
 
intel nvidia

Join Date: Sep 2006
Location: Dekalb, IL
Posts: 2,479

Rep: 203 tofunater is acknowledged by manytofunater is acknowledged by manytofunater is acknowledged by many
Unique Rep: 176
Folding Team Rank: 278
Trader Rating: 24
Default

changed, and I'm still receiving the same error. Thanks for the catch though. +
__________________

Quote:
Originally Posted by iandh View Post
People like this know deep down inside that they are absolutely worthless, so they must constantly come up with new ways to give themselves worth, otherwise they may be tempted to end it all one day by OD'ing on Care-Bears marathons.

System: Hedonism, Stanford Style
CPU
i7 920 D0
Motherboard
Asus P6T6 WS revolution
Memory
6 gigs G-skill
Graphics Card
Tri-sli 260's
Hard Drive
620aaks
Sound Card
on board
Power Supply
Zalman 850
Case
hardwood techstation(soon)
CPU cooling
GTZ/bix 360/355 (soon)
GPU cooling
water (soon)
OS
Vista 64
Monitor
22" Samsung 225BW
Overclock.net - 2009 Chimp Challenge Champions
tofunater is offline I fold for Overclock.net   Reply With Quote
Old 09-02-09   #5 (permalink)
*cough* Stock *cough*
 
muels7's Avatar
 
intel nvidia

Join Date: Jun 2009
Location: Chicago, Illinois
Posts: 650

Rep: 36 muels7 is acknowledged by some
Unique Rep: 34
Folding Team Rank: 1009
Trader Rating: 0
Default

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>>h;
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;
)
here, try this instead


#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 {}
__________________
System: Waste of money..... but who cares!!
CPU
Core 2 Quad Q9650
Motherboard
Gigabyte GA-EP45-UD3P
Memory
8GB G.Skill PC-8500
Graphics Card
EVGA Nvidia 9800GTX+
Hard Drive
2x1TB Seagate Barracuda 7200.12
Sound Card
Creative X-Fi Titanium
Power Supply
Raidmax RX-730SS
Case
APEVIA X-TELSTAR-BK
CPU cooling
Xigmatek Dark Knight
GPU cooling
Stock
OS
Windows 7 Pro x64
Monitor
Asus VH236H

Last edited by muels7 : 09-02-09 at 09:13 PM
muels7 is offline I fold for Overclock.net   Reply With Quote
Old 09-02-09   #6 (permalink)
Folding Fanatic
 
goodolsen's Avatar
 
amd nvidia

Join Date: Jun 2009
Location: Little Elm, TX
Posts: 691

Rep: 48 goodolsen is acknowledged by some
Unique Rep: 37
Folding Team Rank: 275
Team Name: Team Explosm
Trader Rating: 1
Default

p = 3.14159 you area missing the ;
__________________
So you think you're ready to fold...well, then look here:


System: The Little Folder That Could
CPU
Phenom II x3 710
Motherboard
Asus M3N-HT Deluxe
Memory
2x2GB DDR2 800
Graphics Card
3x Asus 9600GSO 96SP folding 24/7
Hard Drive
WD 640GB
Power Supply
OCZ ModXstream 600W
Case
CM Storm Scout
CPU cooling
Mugen 2
GPU cooling
Stock
OS
WinXP Pro SP3
Monitor
Acer 20"
goodolsen is offline I fold for Overclock.net   Reply With Quote
Old 09-02-09   #7 (permalink)
PC Gamer
 
Andru's Avatar
 
intel nvidia

Join Date: Dec 2008
Location: Dublin, CA
Posts: 214

Rep: 21 Andru is acknowledged by some
Unique Rep: 21
Trader Rating: 0
Default

You need to classify p and v as doubles first. Same goes for sae, sas, sac.

System: Woohoo
CPU
Intel Q6700
Motherboard
EVGA 780i
Memory
6 GB OCZ SLI Ready RAM
Graphics Card
9800 GT
Hard Drive
WD 640Gig
Power Supply
Silencer 750w
Case
Cosmos 1000
CPU cooling
Zalman 9700NT
OS
Windows 7 Ultimate 64-bit
Monitor
Samsung 22 inch
Andru is offline   Reply With Quote
Old 09-02-09   #8 (permalink)
Graphics Card Aficionado
 
Drift0r's Avatar
 
intel nvidia

Join Date: Sep 2008
Location: Cali :P
Posts: 1,438

Rep: 82 Drift0r is acknowledged by some
Unique Rep: 77
Hardware Reviews: 1
Trader Rating: 1
Default

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
Quote:
Originally Posted by Andru View Post
You need to classify p and v as doubles first. Same goes for sae, sas, sac.
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.
__________________
Quote:
Originally Posted by Tator Tot View Post
I've been pissing blue for years, is this a problem?
Steam/TF2 Name: [OCN]Rubbish

System: The Blue Aroourourourourua
CPU
Core 2 Duo E7200 @ 3.6GHz
Motherboard
Asus P5E-VM HDMI
Memory
OCZ Platinum Rev.2 PC6400 4GB
Graphics Card
EVGA 9800GT 512MB
Hard Drive
Seagate 500GB SATA 7200RPM
Sound Card
Integrated Realtek HD Audio
Power Supply
Thermaltake Purepower 430W
Case
CoolerMaster Elite 340 mATX
CPU cooling
Xigmatek Dark Knight S1283V
OS
Windows XP Pro SP2 and Vista Ultimate x64
Monitor
Acer X193W+

Last edited by Drift0r : 09-02-09 at 09:14 PM
Drift0r is offline   Reply With Quote
Old 09-02-09   #9 (permalink)
*cough* Stock *cough*
 
muels7's Avatar
 
intel nvidia

Join Date: Jun 2009
Location: Chicago, Illinois
Posts: 650

Rep: 36 muels7 is acknowledged by some
Unique Rep: 34
Folding Team Rank: 1009
Trader Rating: 0
Default

Quote:
Originally Posted by Andru View Post
You need to classify p and v as doubles first. Same goes for sae, sas, sac.
this, i missed it as well.
__________________
System: Waste of money..... but who cares!!
CPU
Core 2 Quad Q9650
Motherboard
Gigabyte GA-EP45-UD3P
Memory
8GB G.Skill PC-8500
Graphics Card
EVGA Nvidia 9800GTX+
Hard Drive
2x1TB Seagate Barracuda 7200.12
Sound Card
Creative X-Fi Titanium
Power Supply
Raidmax RX-730SS
Case
APEVIA X-TELSTAR-BK
CPU cooling
Xigmatek Dark Knight
GPU cooling
Stock
OS
Windows 7 Pro x64
Monitor
Asus VH236H
muels7 is offline I fold for Overclock.net   Reply With Quote
Old 09-02-09   #10 (permalink)
Folding Fanatic
 
tofunater's Avatar
 
intel nvidia

Join Date: Sep 2006
Location: Dekalb, IL
Posts: 2,479

Rep: 203 tofunater is acknowledged by manytofunater is acknowledged by manytofunater is acknowledged by many
Unique Rep: 176
Folding Team Rank: 278
Trader Rating: 24
Default

#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.
__________________

Quote:
Originally Posted by iandh View Post
People like this know deep down inside that they are absolutely worthless, so they must constantly come up with new ways to give themselves worth, otherwise they may be tempted to end it all one day by OD'ing on Care-Bears marathons.

System: Hedonism, Stanford Style
CPU
i7 920 D0
Motherboard
Asus P6T6 WS revolution
Memory
6 gigs G-skill
Graphics Card
Tri-sli 260's
Hard Drive
620aaks
Sound Card
on board
Power Supply
Zalman 850
Case
hardwood techstation(soon)
CPU cooling
GTZ/bix 360/355 (soon)
GPU cooling
water (soon)
OS
Vista 64
Monitor
22" Samsung 225BW
Overclock.net - 2009 Chimp Challenge Champions
tofunater is offline I fold for Overclock.net   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -5. The time now is 03:51 PM.


Overclock.net is a Carbon Neutral Site Creative Commons License

Terms of Service / Forum Rules | Privacy Policy | DMCA Info | Advertising | Become an Official Vendor
Copyright © 2009 Shogun Interactive Development. Most rights reserved.
Page generated in 0.18857 seconds with 8 queries