learning C++

General chitchat, advertisements for other services, and other non-Cantr-related topics

Moderators: Public Relations Department, Players Department

User avatar
N-Aldwitch
Posts: 1771
Joined: Thu Mar 16, 2006 1:48 am
Contact:

Postby N-Aldwitch » Tue Jun 13, 2006 9:51 am

Goto is greatly discouraged in the programming community and it's very, very bad to use when you're programming with others and working for someone.
Nakranoth's "evil" character says:
"Thief! That's terrible! *shakes his head* That would hurt people's feeling if I did that."


http://www.sylorn.com - Free MMORPG in development.. need help.
User avatar
fishfin
Posts: 490
Joined: Mon Mar 20, 2006 12:38 pm
Location: Nanning, China

Postby fishfin » Tue Jun 13, 2006 12:19 pm

Peanut wrote:
fishfin wrote:That was just what I was looking for, thanks.

I probably didn't explane very well what I wanted to do, I want to be able to go back and start running code from line 20 when I get line 100 kind of like it does lots of things (lines 1-99) but on line 100 there is some code telling it to go back to line 20 so it runs code line 20-99 but on line 100 there is some code telling it to go back to line 20 so it runs code line 20-99 but on line 100 there is some code telling it to go back to line 20 so it runs code line 20-99 but on line 100 there is some code telling it to go back to line 20 so it runs code line 20-99 but on line 100 there is some code telling it to go back to line 20 so it runs code line 20-99 but on line 100 there is some code telling it to go back to line 20 so it runs code line 20-99...

And how do you make 'x' something other than a number?


http://www.cprogramming.com/tutorial/lesson3.html

http://www.cprogramming.com/tutorial/lesson4.html


I had read that but didn't understand enugh to do anything with it.
The following statement is not true.

The previous statement is not true.
User avatar
N-Aldwitch
Posts: 1771
Joined: Thu Mar 16, 2006 1:48 am
Contact:

Postby N-Aldwitch » Fri Jun 16, 2006 8:24 am

I prefer php over C++ in general. Learn PHP first...
Nakranoth's "evil" character says:

"Thief! That's terrible! *shakes his head* That would hurt people's feeling if I did that."





http://www.sylorn.com - Free MMORPG in development.. need help.
User avatar
Peanut
Posts: 1155
Joined: Mon Oct 18, 2004 3:01 pm

Postby Peanut » Sat Jun 17, 2006 2:36 pm

N-Aldwitch wrote:I prefer php over C++ in general. Learn PHP first...


Huh?

That's one of the weirdest statements I've ever heard.

Not only that C++ and php aren't related in the most commen way.

Ie it's like comparing webpages to standalone programs.
west
Posts: 4649
Joined: Mon Aug 25, 2003 5:23 pm

Postby west » Sat Jun 17, 2006 8:17 pm

Maybe he means CSS?

/me is learning xhtml and css, finally.
I'm not dead; I'm dormant.
User avatar
fishfin
Posts: 490
Joined: Mon Mar 20, 2006 12:38 pm
Location: Nanning, China

Postby fishfin » Sat Jul 01, 2006 1:08 am

I have another question...
When I first started learning C++ I wrote a calculator in it just to practice.
A few days ago I decided to try to add a square root function to it but I can't seem to get it to work.
cout<<"Enter the first number:";
cin>> number1;
cin.ignore();
number1 = answer * answer;
cout<<"The square root of "<<number1 <<" is "<<answer <<".";


cout<<"Enter the first number:";
cin>> number1;
cin.ignore();
number1 = number2 * answer;
number2 = anwer;
cout<<"The square root of "<<number1 <<" is "<<answer <<".";

I tried both of those, maybe I'm just doing something wrong?
The following statement is not true.



The previous statement is not true.
Lord_Igor
Posts: 97
Joined: Tue Jun 29, 2004 4:08 pm

Postby Lord_Igor » Sat Jul 01, 2006 9:54 am

Yes, you are doing it wrong.

Code: Select all

number1 = answer * answer;

This will give number1 the value of answer times itself. The earlier inputted value is lost. The value of answer is most likely not what you want it to be. I am assuming you declared both variables earlier or else it won't compile.

Code: Select all

number1 = number2 * answer;
number2 = anwer;

I will first ignore you're typo. The first line will give number1 the value of number2 times answer. The inputted value is lost here also. The second line will then give number2 the value of answer.

What you want to do is use the function sqrt(). It will return the square root of the number given as argument. You must include the math library.

Code: Select all

cout<<"Enter the first number:";
cin>> number1;
cin.ignore();
answer = sqrt(number1);
cout<<"The square root of "<<number1 <<" is "<<answer <<".";
User avatar
fishfin
Posts: 490
Joined: Mon Mar 20, 2006 12:38 pm
Location: Nanning, China

Postby fishfin » Sat Jul 01, 2006 11:03 am

I tried:
cout<<"Enter the first number:";
cin>> number1;
cin.ignore();
answer = sqrt(number1);
cout<<"The square root of "<<number1 <<" is "<<answer <<".";


but I got an error saying:
'sqrt' undeclared (first use this function)


I use Dev-C++.[/quote]
The following statement is not true.



The previous statement is not true.
Lord_Igor
Posts: 97
Joined: Tue Jun 29, 2004 4:08 pm

Postby Lord_Igor » Sat Jul 01, 2006 1:36 pm

Did you include math.h?
User avatar
fishfin
Posts: 490
Joined: Mon Mar 20, 2006 12:38 pm
Location: Nanning, China

Postby fishfin » Sun Jul 02, 2006 12:20 am

no, I'll try that.
The following statement is not true.



The previous statement is not true.
User avatar
Birdsall007
Posts: 118
Joined: Tue Nov 30, 2004 12:40 pm
Location: Northampton, England

Postby Birdsall007 » Tue Jul 04, 2006 12:33 pm

How's it going? Did you get the looping to work?
Even if the voices aren't real...They have some pretty good ideas!
User avatar
fishfin
Posts: 490
Joined: Mon Mar 20, 2006 12:38 pm
Location: Nanning, China

Postby fishfin » Wed Jul 05, 2006 3:57 pm

no, I haven't goten the looping to work (I haven't tried very hard either), but the square root works (thanks for the help).
The following statement is not true.



The previous statement is not true.
User avatar
fishfin
Posts: 490
Joined: Mon Mar 20, 2006 12:38 pm
Location: Nanning, China

Postby fishfin » Sat Jul 08, 2006 6:35 am

I've figured out how to make loops!!

but I still haven't figured out how to check to see if a word has been entered (I couldn't think of a better way to describe it)

Here is what I've been trying:
#include <iostream>
#include <string>

using namespace std;

int main()
{
char pass;

cout<<"enter password:";
cin>> pass;
cin.ignore();

if ( pass == password ) {
cout<<"correct!";
cin.get();
}
}


I get this warning saying: 'password' undeclared (first use this function)
The following statement is not true.



The previous statement is not true.
Lord_Igor
Posts: 97
Joined: Tue Jun 29, 2004 4:08 pm

Postby Lord_Igor » Sat Jul 08, 2006 9:24 am

fishfin wrote:I get this warning saying: 'password' undeclared (first use this function)

As it says, you need to declare password. E.g.

Code: Select all

char password;


Though, the way you have it written now the password will only be one character long. Also you need to give password a value. I suggest either declaring pass and password like

Code: Select all

char pass[20];
char password[20] = "fishfinisbest";

and then use strcmp(), include string.h,

Code: Select all

if (strcmp(pass,password)==0) {...}

or you could use String

Code: Select all

String pass;
String password = "fishfinisbest";
...
if (pass == password) {...}
User avatar
fishfin
Posts: 490
Joined: Mon Mar 20, 2006 12:38 pm
Location: Nanning, China

Postby fishfin » Sat Jul 08, 2006 11:11 am

I did this:
#include <iostream>
#include <string>

using namespace std;

int main()
{
char pass1[8], pass2[8] = "password";

cout<<"enter password:";
cin>> pass1;
cin.ignore();

if ( strcmp ( pass1, pass2 ) == 0 ) {
cout<<"correct!";
cin.get();
}
}


and I got a warning saying: initializer-string for array of chars is to long
The following statement is not true.



The previous statement is not true.

Return to “Non-Cantr-Related Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest