09-15-2005, 07:08 PM | #21 |
FFR Player
|
Soccr's console idea was right. You can do it Nipunn's way without getting any errors or warnings, but you would probably get some sort of logic error. I tried it in one of my programs, it built fine, but it didn't work. I don't remember if there was another problem or if that was it, though.
In any case, it's just better to use the << or the >> operators with the console instead of commas. For now, at least. postcount++;
__________________
Signature subject to change. THE ZERRRRRG. |
09-15-2005, 07:27 PM | #22 | |
FFR Player
Join Date: Dec 2003
Location: At My House
Posts: 989
|
Re: RE: Re: C++ Help
Quote:
Code:
#include <iostream> #include <stdlib> using namespace std; int main() { char asdfString[5] = "54.2"; float asdfFloat; asdfFloat = atof(asdfString); return 0; }
__________________
|
|
09-15-2005, 07:44 PM | #23 | |
Guest
Posts: n/a
|
Re: RE: Re: C++ Help
Quote:
I clicked a link called "Flash Flash Revolution" once, on a whim... ...and here I am. |
|
09-15-2005, 11:31 PM | #24 |
Resident Penguin
|
RE: Re: RE: Re: C++ Help
jurs' guido's right on... it just tells you more than you want to know.
|
09-16-2005, 12:56 AM | #25 |
is against custom titles
|
RE: Re: RE: Re: C++ Help
Basically, what I wrote is everything you need besides the proper equations. So, if you cut out everything past the precision setting and put in what really needs to be there (I just left chicken's math alone), you'll have a program that does what you want.
--Guido http://andy.mikee385.com |
09-16-2005, 08:14 AM | #26 |
FFR Player
Join Date: May 2002
Posts: 1,088
|
RE: Re: RE: Re: C++ Help
I entered that, and it wasn't right/there was some kind of error/it's not coded like my other projects. Here's an example of how i'm learning it(a previous project):
Code:
#include <iostream> using namespace std; int main() { int years, months, days; cout<<"How many years old are you? "; cin>>years; cout<<endl; cout<<"How many months past your years are you? "; cin>>months; cout<<endl; cout<<"How many remaining days old are you? "; cin>>days; cout<<endl; cout<<"The numbers you entered are "<<years<<" for years, "<<months<<" for remaining months, and "<<days<<" for days. "; cout<<endl; int totalMonths, totalDays; totalMonths=years*12+months; totalDays=years*360+days; cout<<"You are approximately "<<totalMonths<<" months old. "; cout<<endl; cout<<"You are approximately "<<totalDays<<" days old. "; cout<<endl; return 0; } |
09-16-2005, 08:41 AM | #27 |
is against custom titles
|
RE: Re: RE: Re: C++ Help
So just move my code around. The only thing that's structurally different from what you just posted and what I posted is you using int main() and me using void main(), which won't make a difference and you shouldn't worry about (unless you're returning 0 in void main or something).
Like I said, rearrange all of my body however you wish to follow whatever format you want. You say what I posted isn't coded like your older project, but I don't see a difference that would matter. If you got a syntax error, tell us what it is. --Guido http://andy.mikee385.com |
09-16-2005, 03:39 PM | #28 |
FFR Player
|
RE: Re: RE: Re: C++ Help
How could they not get an error with code like that? They never declared any variables. XD
I would imagine that they would, though.
__________________
Signature subject to change. THE ZERRRRRG. |
10-6-2005, 03:16 PM | #29 |
lil j the bad b-word
|
RE: Re: RE: Re: C++ Help
Hi again. I need help with some other program...I have what I did saved on floppy disk but I forgot that I don't have a floppy drive >_>
Anyways, I use Microsoft Visual Basic thing...so that's what it has to input into. Here's the thing. Write a program that prompts the user to input x-y coordinate of a point in a Cartesian Plane. The program should output a message indicating whether the point is on the origin, x or y axis, or in a particular quadrant. I'm pretty sure you have to do the if stuff, etc. Anyone who can help me do it for my class tomorrow morning gets a present >_>
__________________
|
10-6-2005, 03:28 PM | #30 |
Resident Penguin
|
RE: Re: RE: Re: C++ Help
uh here's the logic, not the language:
input x, input y if x==0 and y==o then output "origin" if x==0 and y!=0 then output "x-axis" if y==0 and x!=0 then output "y-axis" if x > 0 and y > 0 then output "first quadrant" if x < 0 and y > 0 then output "second quadrant" if x<0 and y<0 then output "third quadrant" if x>0 and y<0 then output "fourth quadrant" fairly tedious. I'm sure there's a sexier way to do it. |
10-6-2005, 05:59 PM | #31 |
FFR Player
|
RE: Re: RE: Re: C++ Help
You messed up your logic for the x and y axis stuff...
Should be: input x, input y if x==0 and y==0 then output "origin" else if x==0 and y!=0 then output "y-axis" else if y==0 and x!=0 then output "x-axis" else if x > 0 and y > 0 then output "first quadrant" else if x < 0 and y > 0 then output "second quadrant" else if x<0 and y<0 then output "third quadrant" else if x>0 and y<0 then output "fourth quadrant" That is far from tedious as far as code goes... -----Soccr743----- |
10-6-2005, 07:25 PM | #32 |
Resident Penguin
|
RE: Re: RE: Re: C++ Help
oh yeah. ::
|
10-6-2005, 08:35 PM | #33 |
Away from Computer
|
RE: Re: RE: Re: C++ Help
Code:
#include <iostream> main() { int x,y; cout << "enter an x and a y"; cin >> x; cin >> y; if x==0 && y==0 cout << "origin"; if x==0 && y!=0 cout << "y-axis"; if y==0 && x!=0 cout << "x-axis"; if x > 0 && y > 0 cout << "first quadrant"; if x < 0 && y > 0 cout << "second quadrant"; if x<0 && y<0 cout << "third quadrant"; if x>0 && y<0 cout << "fourth quadrant" ; } Edit for bad include syntax <_<
__________________
|
10-6-2005, 09:30 PM | #34 |
Resident Penguin
|
RE: Re: RE: Re: C++ Help
you forgot the most important part.
I'll let you try to figure out where it is... |
10-6-2005, 09:36 PM | #35 |
FFR Player
|
RE: Re: RE: Re: C++ Help
Gosh, I can't figure it out, Talis (or can I?).
If you read that sentence above and you have a brain, you'd know I know what the errors would be. Oh, snap, I read the code again and there's actually another, much more glaring error in Nipunn's code. How could you, man? I always add that in first. Also, you should declare a namespace. It's a good practice. Also, you should make x and y doubles, then ask for their input on the same line (as in, cin >> x >> y. You just need a space between the two numbers when you input them. Also, you should use newlines and grammar to spice it up.
__________________
Signature subject to change. THE ZERRRRRG. |
10-6-2005, 09:52 PM | #36 |
Away from Computer
|
Re: RE: Re: RE: Re: C++ Help
Code:
#include <iostream> main() { using std::namespace int x,y; cout << "enter an x and a y"; cin >> x >> y; if x==0 && y==0 cout << "origin"; if x==0 && y!=0 cout << "y-axis"; if y==0 && x!=0 cout << "x-axis"; if x > 0 && y > 0 cout << "first quadrant"; if x < 0 && y > 0 cout << "second quadrant"; if x<0 && y<0 cout << "third quadrant"; if x>0 && y<0 cout << "fourth quadrant" ; } and cin both on the same line I stole all the words from talisman/sccr plus I forget how to newline >_> is it like std::endl or can I just cout a "\n"
__________________
|
10-6-2005, 10:20 PM | #37 |
FFR Player
|
RE: Re: RE: Re: RE: Re: C++ Help
You can newline two ways.
Here is and example of each: cout << "Cock goes where?\n"; cout << "Cock goes over there. -->" << endl; Okay. By the way, you should probably stick the namespace right under your includes. It's just easier than sticking it into every single function in the program. And since you missed it: You forgot to return 0! You also forgot to put parentheses around your conditionals. Shame, man. :P
__________________
Signature subject to change. THE ZERRRRRG. |
10-6-2005, 10:45 PM | #38 |
is against custom titles
|
Re: RE: Re: RE: Re: C++ Help
Code:
#include <iostream> using namespace std; void main() { double x,y; cout << "enter an x and a y"; cin >> x; cin >> y; if x==0 && y==0 cout << "origin"; if x==0 && y!=0 cout << "y-axis"; if y==0 && x!=0 cout << "x-axis"; if x > 0 && y > 0 cout << "first quadrant"; if x < 0 && y > 0 cout << "second quadrant"; if x<0 && y<0 cout << "third quadrant"; if x>0 && y<0 cout << "fourth quadrant" ; } --Guido http://andy.mikee385.com |
10-6-2005, 11:26 PM | #39 |
Resident Penguin
|
RE: Re: RE: Re: RE: Re: C++ Help
yeah... I was going for the return 0; part... otherwise any half decent compiler will rape you if you try to make it compile that code.
|
10-7-2005, 02:43 PM | #40 |
Away from Computer
|
Re: RE: Re: RE: Re: C++ Help
Code:
#include <iostream> main() { using std::namespace int x,y; cout << "enter an x and a y \n"; cin >> x >> y; if (x==0 && y==0) cout << "origin"; if (x==0 && y!=0) cout << "y-axis"; if (y==0 && x!=0) cout << "x-axis"; if (x > 0 && y > 0) cout << "first quadrant"; if (x < 0 && y > 0) cout << "second quadrant"; if (x<0 && y<0) cout << "third quadrant"; if (x>0 && y<0) cout << "fourth quadrant" ; } silly me anyway, even though its too late I feel the need to fix it you can do a main without a return I believe.
__________________
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|