learning C++
Moderators: Public Relations Department, Players Department
- N-Aldwitch
- Posts: 1771
- Joined: Thu Mar 16, 2006 1:48 am
- Contact:
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.
"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.
- fishfin
- Posts: 490
- Joined: Mon Mar 20, 2006 12:38 pm
- Location: Nanning, China
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.
The previous statement is not true.
- N-Aldwitch
- Posts: 1771
- Joined: Thu Mar 16, 2006 1:48 am
- Contact:
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.
"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.
- Peanut
- Posts: 1155
- Joined: Mon Oct 18, 2004 3:01 pm
-
- Posts: 4649
- Joined: Mon Aug 25, 2003 5:23 pm
- fishfin
- Posts: 490
- Joined: Mon Mar 20, 2006 12:38 pm
- Location: Nanning, China
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.
I tried both of those, maybe I'm just doing something wrong?
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.
The previous statement is not true.
-
- Posts: 97
- Joined: Tue Jun 29, 2004 4:08 pm
Yes, you are doing it wrong.
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.
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
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 <<".";
- fishfin
- Posts: 490
- Joined: Mon Mar 20, 2006 12:38 pm
- Location: Nanning, China
I tried:
but I got an error saying:
I use Dev-C++.[/quote]
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.
The previous statement is not true.
- fishfin
- Posts: 490
- Joined: Mon Mar 20, 2006 12:38 pm
- Location: Nanning, China
- Birdsall007
- Posts: 118
- Joined: Tue Nov 30, 2004 12:40 pm
- Location: Northampton, England
- fishfin
- Posts: 490
- Joined: Mon Mar 20, 2006 12:38 pm
- Location: Nanning, China
- fishfin
- Posts: 490
- Joined: Mon Mar 20, 2006 12:38 pm
- Location: Nanning, China
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:
I get this warning saying: 'password' undeclared (first use this function)
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.
The previous statement is not true.
-
- Posts: 97
- Joined: Tue Jun 29, 2004 4:08 pm
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) {...}
- fishfin
- Posts: 490
- Joined: Mon Mar 20, 2006 12:38 pm
- Location: Nanning, China
I did this:
and I got a warning saying: initializer-string for array of chars is to long
#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.
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