| View previous topic :: View next topic |
| Author |
Message |
smwilliam2 Soul Rider

Joined: 16 Apr 2006 Posts: 252
|
Posted: Apr 25, 2007 12:25 pm Post subject: C++ ANYONE? |
|
|
i am suppose to right this program. Have no understanding of C++ and I am sure it would take anyone like 5 min to write up could anyone help me out? Below is what I am to do:
Ask the user to enter a radius, calculate (and output) the circumference and area of the circle.
C= 2(pi)r
A=(pi)r^2
-use variable pi and set it to 3.14159 |
|
| Back to top |
|
 |
|
|
Wakebrad Ladies Man


Joined: 11 Dec 2003 Posts: 12257 City: Dallas
|
Posted: Apr 25, 2007 12:44 pm Post subject: |
|
|
It's been a couple years but here goes:
#include <iostream>
using namespace std;
int main()
{
double r;
double pi = 3.14159;
cout << "Enter the radius: ";
cin >> r;
cout << "The circumference is: " << 2.0*pi*r << " the area is: " << 1.0*pi*r^2 << endl;
return 0;
} _________________ You have just entered the twilight zone. |
|
| Back to top |
|
 |
Wakebrad Ladies Man


Joined: 11 Dec 2003 Posts: 12257 City: Dallas
|
Posted: Apr 25, 2007 12:52 pm Post subject: |
|
|
Oh, if that works the first time you owe me $5. You can PM me for my paypal.
Software never works the first try. _________________ You have just entered the twilight zone. |
|
| Back to top |
|
 |
smwilliam2 Soul Rider

Joined: 16 Apr 2006 Posts: 252
|
Posted: Apr 25, 2007 3:04 pm Post subject: |
|
|
alright I will let you know tomorrow once i get into the computer lab and try it..
i dont think i will ever make fun of a cis major again... this crap makes no sence to me |
|
| Back to top |
|
 |
smwilliam2 Soul Rider

Joined: 16 Apr 2006 Posts: 252
|
Posted: Apr 26, 2007 12:22 pm Post subject: |
|
|
got two errors
cin >> r; this line has an error of "unable to resolve function overload"
and
cout << "The circumference is: " << 2.0*pi*r << " the area is: " << 1.0*pi*r^2 << endl; has an error of mismath in formal parameter list |
|
| Back to top |
|
 |
smwilliam2 Soul Rider

Joined: 16 Apr 2006 Posts: 252
|
Posted: Apr 26, 2007 12:39 pm Post subject: |
|
|
| cin >> r; this line is fine both errors are on the the other one i guess |
|
| Back to top |
|
 |
Wakebrad Ladies Man


Joined: 11 Dec 2003 Posts: 12257 City: Dallas
|
Posted: Apr 26, 2007 12:44 pm Post subject: |
|
|
Sounds like your environment might not be setup right.
Try this one to see if you can at least get it to execute:
#include <iostream>
using namespace std;
int main()
{
double r;
cout<<"test";
return 0;
} _________________ You have just entered the twilight zone. |
|
| Back to top |
|
 |
Wakebrad Ladies Man


Joined: 11 Dec 2003 Posts: 12257 City: Dallas
|
Posted: Apr 26, 2007 12:45 pm Post subject: |
|
|
if they're both on that one line try this then:
#include <iostream>
using namespace std;
int main()
{
double r;
double pi = 3.14159;
cout << "Enter the radius: ";
cin >> r;
cout << "The circumference is: " << 2.0*pi*r << " the area is: " << 1.0*pi*r*r << endl;
return 0;
} _________________ You have just entered the twilight zone. |
|
| Back to top |
|
 |
smwilliam2 Soul Rider

Joined: 16 Apr 2006 Posts: 252
|
Posted: Apr 26, 2007 12:52 pm Post subject: |
|
|
| dude you are the man |
|
| Back to top |
|
 |
smwilliam2 Soul Rider

Joined: 16 Apr 2006 Posts: 252
|
Posted: Apr 26, 2007 12:52 pm Post subject: |
|
|
| what did you change? |
|
| Back to top |
|
 |
b_girl Wakeboarder.Commie

Joined: 10 Jul 2006 Posts: 1423 City: Toronto
|
Posted: Apr 26, 2007 12:53 pm Post subject: |
|
|
not to sound b***hy or anything but u coulda at least attempted it yourself before asking someone else to write it for you!
anyway, add this to the top:
#include "stdafx.h"
*edit* or not... haha, it's been a couple years since i touched C++ |
|
| Back to top |
|
 |
smwilliam2 Soul Rider

Joined: 16 Apr 2006 Posts: 252
|
Posted: Apr 26, 2007 12:56 pm Post subject: |
|
|
because I did try it myself.. this stuff means nothing to me i dont understand it one bit, the last assignment we had was to copy what he had and put it and and i got errors with no clue how to fix.
this is a intro class i took it as a gen ed aside from this the class was a joke. |
|
| Back to top |
|
 |
smwilliam2 Soul Rider

Joined: 16 Apr 2006 Posts: 252
|
Posted: Apr 26, 2007 12:57 pm Post subject: |
|
|
#include "stdafx.h"
what does this do? |
|
| Back to top |
|
 |
Wakebrad Ladies Man


Joined: 11 Dec 2003 Posts: 12257 City: Dallas
|
Posted: Apr 26, 2007 1:05 pm Post subject: |
|
|
Ok, now that you know the problem and have the solution in front of you here's a little explanation.
#include <iostream>To write data to and from the screen you have to include this code so that the compiler recognises cin and cout
using namespace std;this defines the namespace, too complex to worry about yet
int main()This is where the code starts executing
{defines the opening of the function
double r;Declares a variable of type double. Integer is like 1,2,3,4,5. Double can have decimals: 2.4, 4.003, etc
double pi = 3.14159;define pi as a double and set it to the value
cout << "Enter the radius: ";cout<< writes to the screen
cin >> r;cin>> reads the screen into the variable r
cout << "The circumference is: " << 2.0*pi*r << " the area is: " << 1.0*pi*r*r << [/b]endl;This is the line with the problem. My mistake was that I thought r^2 would do exponent but I was wrong. What I changed it to was r*r.
return 0;This is the return value, you probably don't need to worry about this yet. Read your book or wait until your prof goes over functions/methods
}this closes the function
Your prof should have gone over some of this stuff already. _________________ You have just entered the twilight zone. |
|
| Back to top |
|
 |
smwilliam2 Soul Rider

Joined: 16 Apr 2006 Posts: 252
|
Posted: Apr 26, 2007 1:08 pm Post subject: |
|
|
wow i somewhat understand it actually, thank you. the prof is not a very helpful one he runs through slides in monolouge; I am sure you know a few profs like this.
Seriously, you have no idea how much you helped me out. I appreciate it |
|
| Back to top |
|
 |
DJew Jake Wakeboarder.com Freak


Joined: 17 Sep 2003 Posts: 3907 City: Toronto
|
Posted: Apr 26, 2007 1:14 pm Post subject: |
|
|
If your taking the course are you going to expect us to write all your assignments? _________________ They know what is what but they dono what is what they just strut. |
|
| Back to top |
|
 |
smwilliam2 Soul Rider

Joined: 16 Apr 2006 Posts: 252
|
Posted: Apr 26, 2007 1:16 pm Post subject: |
|
|
| yeah can you get on my excel spreadsheets while your helping me out with this? |
|
| Back to top |
|
 |
Wakebrad Ladies Man


Joined: 11 Dec 2003 Posts: 12257 City: Dallas
|
Posted: Apr 26, 2007 1:21 pm Post subject: |
|
|
I've had some profs like that, it's particularly bad in intro classes where the subject is totally new. The best way to learn is to use your book, type out the examples and run them.
No problem. _________________ You have just entered the twilight zone. |
|
| Back to top |
|
 |
DJew Jake Wakeboarder.com Freak


Joined: 17 Sep 2003 Posts: 3907 City: Toronto
|
Posted: Apr 26, 2007 1:25 pm Post subject: |
|
|
the reason ^ did not work is because that is a bit op in c++ when you go numbe^2 its xor with 2 isnt it? _________________ They know what is what but they dono what is what they just strut. |
|
| Back to top |
|
 |
b_girl Wakeboarder.Commie

Joined: 10 Jul 2006 Posts: 1423 City: Toronto
|
Posted: Apr 26, 2007 1:26 pm Post subject: |
|
|
| smwilliam2, sorry, didn't realize you had already tried it yourself. i've been roped into "helping" (or... doing) other peoples assignments before so i get a little annoyed by it now if the person hasn't at least made an attempt first. |
|
| Back to top |
|
 |
DJew Jake Wakeboarder.com Freak


Joined: 17 Sep 2003 Posts: 3907 City: Toronto
|
Posted: Apr 26, 2007 1:27 pm Post subject: |
|
|
incase your wonderng that means
lets sa radius - 7 thats 00000111
2 = 00000010
xor means one or the other but not both so the awsner would be
00000101 or 5 _________________ They know what is what but they dono what is what they just strut. |
|
| Back to top |
|
 |
DJew Jake Wakeboarder.com Freak


Joined: 17 Sep 2003 Posts: 3907 City: Toronto
|
Posted: Apr 26, 2007 1:28 pm Post subject: |
|
|
but bit ops do not work on floating numbers thats why it didnt work. _________________ They know what is what but they dono what is what they just strut. |
|
| Back to top |
|
 |
smwilliam2 Soul Rider

Joined: 16 Apr 2006 Posts: 252
|
Posted: Apr 26, 2007 1:29 pm Post subject: |
|
|
| b_girl, yeah this is a forum where every gets on eachothers cases. but how do find yourself in doing stuff for others i mean you have a choice... maybe sub consciously you enjoy helping others lol |
|
| Back to top |
|
 |
b_girl Wakeboarder.Commie

Joined: 10 Jul 2006 Posts: 1423 City: Toronto
|
Posted: Apr 26, 2007 1:33 pm Post subject: |
|
|
smwilliam2, it starts out with them asking for help on how to start it... then help on how to do such-and-such, etc... and before you know it, i've done the whole thing. so now i'm a little more careful when people ask for help
some people just cut right to the chase and ask me to do the whole thing... but then they're met with a big fat no. |
|
| Back to top |
|
 |
DJew Jake Wakeboarder.com Freak


Joined: 17 Sep 2003 Posts: 3907 City: Toronto
|
Posted: Apr 26, 2007 1:38 pm Post subject: |
|
|
I refuse to write you any code in c its so useless these days. Sorry. _________________ They know what is what but they dono what is what they just strut. |
|
| Back to top |
|
 |
Wakebrad Ladies Man


Joined: 11 Dec 2003 Posts: 12257 City: Dallas
|
Posted: Apr 26, 2007 1:40 pm Post subject: |
|
|
Wow, I haven't done C++ in 5 years. That's crazy. It doesn't seem like that long ago.
Interesting on the xor. Not sure I ever used that. I had a course in C and a course in C++ but work in ASP.NET and Java now.
I mooched off more people in highschool and college than I will ever be able to make up for. It feels good to give back a little  _________________ You have just entered the twilight zone. |
|
| Back to top |
|
 |
DJew Jake Wakeboarder.com Freak


Joined: 17 Sep 2003 Posts: 3907 City: Toronto
|
Posted: Apr 26, 2007 1:47 pm Post subject: |
|
|
Wakebrad, Ye well why use c++ managed languages are just as fast and you can insert assembler directly into them too so as far as im concrened c++ has very little use in todays world of on demand applications. _________________ They know what is what but they dono what is what they just strut. |
|
| Back to top |
|
 |
Wakebrad Ladies Man


Joined: 11 Dec 2003 Posts: 12257 City: Dallas
|
Posted: Apr 26, 2007 1:58 pm Post subject: |
|
|
Jibsta, interesting. I hadn't heard that C++ was on its way out.
I pretty much only do web apps so c++ has no use there. C# is going strong though. _________________ You have just entered the twilight zone. |
|
| Back to top |
|
 |
DJew Jake Wakeboarder.com Freak


Joined: 17 Sep 2003 Posts: 3907 City: Toronto
|
Posted: Apr 26, 2007 2:14 pm Post subject: |
|
|
Wakebrad, Well c has obvious uses for anything low level. But 90% of user apps are now writen in managed code. Languages like C# lets big companies higher less skilled in house programmers for cheaper so its win win for everyone. Anything "hard" to write will still be done in c++. _________________ They know what is what but they dono what is what they just strut. |
|
| Back to top |
|
 |
b_girl Wakeboarder.Commie

Joined: 10 Jul 2006 Posts: 1423 City: Toronto
|
Posted: Apr 27, 2007 3:08 pm Post subject: |
|
|
c# is the way forward for sure, i haven't done that much in it yet, but i intend to... most of my experience in the past actually lies in C and C++... doing VB at my current job though...
wanna know something sad? we still update/support VB3 apps. our boss has been very hesitant to move to VB.Net - partially cuz he's got no clue what it is. BUT, think we've managed to convince him to allow us to start moving portions of our apps across to .net now.
Wakebrad, my project over the next few weeks is actually to redesign this one product of ours so it's accessible over the web (it's currently a 16-bit app so it's gonna take some work), so that means asp.net... i might come to you with questions  |
|
| Back to top |
|
 |
Wakebrad Ladies Man


Joined: 11 Dec 2003 Posts: 12257 City: Dallas
|
Posted: Apr 27, 2007 6:21 pm Post subject: |
|
|
b_girl, haha no problem. I'm actually just making the switch to 2.0 so I'm still learning the new stuff but once you get the concept you should be fine. also www.asp.net has pretty helpful forums that I use when I'm stumped. _________________ You have just entered the twilight zone. |
|
| Back to top |
|
 |
b_girl Wakeboarder.Commie

Joined: 10 Jul 2006 Posts: 1423 City: Toronto
|
Posted: Apr 28, 2007 9:51 am Post subject: |
|
|
Wakebrad, thanks - i'll keep that link in mind, except we don't have use of the internet at work  |
|
| Back to top |
|
 |
|
|
|