Just look at this post and you'll see you've made a mistake in your code ...
lllllIllIlllI commented: Cheers, a little bit closer to understanding :) +2
It's working for determining if the sum is even or not. The Sum mod 2 remains the same.
Can you explain we how it (your example using strings) was working ??
Using string operations:
string a; unsigned short int Sum=0,i; a="12522"; for(i=0;i<a.length();i++) Sum+=a[i];
This code isn't returning the sum of the digits in the number !!
And that's the code you prefer ? Code which isn't working ??!!
Dear unbeatable, to make your code work change it to the following:
string a;
unsigned short int Sum=0,i;
a="12522";
for(i=0;i<a.length();i++) Sum+=a[i]-'0';
When you don't need to do calculations with the number there's no reason for doing the mathematical operations on it - you have the possibility to separate the characters more easily usign strings.
Not agreed, using strings is more processor intensive, dealing with numbers is actually a speed boost ...
BTW, You can get the last digit of a number using the modulo operator like this: lastdigit = number % 10;
Why are you hard coding the username and password in the code, if you want to improve your login system (make it more universal) you could make an account database where the username and password are stored in ...
Edit:: You could also use a bool
called 'terminate', and you let your while run like this while(!terminate)
...
Edit:: It's also a bad security practice when you're notifying the user when a username doesn't exist, it would be better if you ask the user to enter a username and a password, and when one of these is wrong you simply notify the user with "Wrong username or password" ...
What type of variable is X2, I guess it's probably an integer, which can't store floating numbers ...
Use a float
instead ...
I am trying to link an object files to the library files.
To create a static library from an object file you just need to invoke the following command: ar -rv lib[U]yourlibfilename[/U].a [U]yourobjectfile[/U].o
FILE should be defined in <cstdio> (or <stdio.h> for C)
Using #include <stdio.h>
the code is compiling with me :) ...
You declare the first arrAscendingOrder and showArrPtr paremeter as an array of pointers to double ( Why?! )
I also don't understand exactly why he's doing it in that way ...
To the OP: Array's names are actually constant pointers to the first element of the array, so if you intended to pass a pointer to the array, you were already doing it in the wrong way ...
If you pass an array to a function, a constant pointer to the first element of the array is passed to the function ...
Yup, if you're using the getline
or cin.get(charvar, number_of_chrs)
methods/functions, you always have to bear in mind the '\n' character stays in the input buffer ...
But as already mentioned there's an extensive thread about it ...
I think FILE
is throwing the error (line 98): AGENTDEBUG_PUBLIC FILE *gp_fPtr;
As it isn't defined somewhere ...
I don't understand - why do you have the numbers input as 'int'? Why don't you have the numbers input directly into a string and then use the operator [] to move through the digits and count values? I think it could be much more efficient - just run a loop like
for(index=0;index<number.length();index++)
and add every digit to a variable that holds the sum. If you assume ASCII, you won't even need to convert the character digits into digits, because their ASCII values are even for even digits.
I actually don't understand why you need a string for that purpose, you can do it using mathematical operations only.
Why making it difficult if it can be easy ?
Look at ArkM's post ! :)
I think the following link will help you:
http://nerds-central.blogspot.com/2007/09/how-to-get-sid-for-group-or-user-by.html
Yes, the information is correct, but it isn't explaining much (e.g: a namespace is not only used to share some constant values) ...
Namespaces:
e.g. a variable called 'animal' declared in namespace A
won't conflict with a variable called 'animal' declared in namespace B
...
Static variables are often used in classes (because you can share the same variable among all the objects created from the class) ...
e.g. If you want to count the number of instances a class has, without having to use a global variable ...
A static variable is stored in the static memory of your computer, static variables are also used sometimes in functions: normally all the function's local variables are lost when a function exits, but if you declare a static variable in a function, the variable won't be gone after the function has exited, a static variable stays in memory until the program exits
I hope I explained everything correctly and in a way you can understand it ...
If you still have questions, please feel free to ask ...
Edit::
-> http://www.cprogramming.com/tutorial/namespaces.html
-> http://www.cprogramming.com/tutorial/statickeyword.html
Probably if you try searching Google you'll find some other information about it ...
should i try to make an algorithm that checks if the first number's sum of digits is even and than to count the interval until 9 is reached and than to switch? example:
289-false
290-false
291-true
292-false
293-true
....
299-true
300-false
and than to count the true ones
No, you only have to write a function which calculates the sum of the digits of a number (using the information mentioned in my previous post (look at the link) and ArkM's post) ...
no man. u r again wrong..
i m using smarty... so there is no need to define <?php between <a href>..................
I said I'm not good at PHP,
I meant something like this:
#1:
<?php
$URL = "./index.php?_act=manageregister&DO=manageProfile&intUserID=";
$URL .= $data[i].intUserID;
?>
#2:
<a href="<?php echo $URL; ?>"><span>Edit Profile</span></a>
Could you please try it?
-> First create a string variable called URL
-> Now we're adding all the content (the variables) to it to build up the entire URL ...
-> Inside the <a href> tag we use <?php echo URL;> to write the URL into the tag ...
Does this help ?
try to give better suggestions mr.tux.
I think it has to do with some php-tags you should place in the <a href> tag, not sure where they have to be but you could try ...
First, I'm not a PHP professional and please don't blame me if my suggestions aren't working, but maybe you should try this:
<a href="./index.php?_act=manageregister&DO=manageProfile&intUserID={$data[i].intUserID}"><span>Edit Profile</span></a>
<a href="./index.php?_act=manageregister&DO=manageDesiredProfile&intUserID={$data[i].intUserID}"><span>Edit Desired Profile</span></a>
<a href="./index.php?_act=manageregister&DO=manageImages&intUserID={$data[i].intUserID}"><span>Edit Images</span></a>
Using double-quotes instead of single ones ...
Does that help ?
On line 98 I'm also getting an error when I'm compiling this:
Error E2141 testt.cpp 98: Declaration syntax error
I think the following algorithm is a better one:
If you know the starting number of the interval:
-> Check whether the sum of it's digits are even (you could use the modulo operator for this)
-> If the sum was even, you automatically know the next number's sum of digits is odd
e.g: 450 => odd ; 451 => even ; 452 => odd ; 453 => even ; etc. ...
Edit:: So actually you don't have to check each number's sum of digits
Hope this helps ! :)
After I did that my compiler stopped working. I tried it on Dev C++ and Microsoft Visual C++2008. Both of them stopped working. :(
Could you post me the whole code which broke your compiler ?
I would like to try it :twisted: ...
To the OP: I would like to notice you that your function getArray()
is returning a constant value which means the value it returns isn't changeable ...
If you want your function returning editable values you should change it to something like this:
char* getArray(const string & s)
{
char * modif = new char[strlen(s.c_str())+1];
strcpy(modif, s.c_str());
return modif;
}
NOTE: If you're using this function please don't forget to delete the assigned memory ...
Can you explain why you have invented so strange manner to die for your top secret application? ;)...
:P
Yeah, that's all OK, but can you post the code you have so far, and ask specific questions about what you don't understand ?
Edit:: I think you're supposed to create a class hierarchy ...
.NET is probably working best if you're using a Microsoft compiler together with other MS related stuff, if you really want to develop for .NET I would like to recommend you to use their stuff ...
Maybe the following information might be useful for you:
http://www.codersource.net/c++_vector_stl.html
Ah i didnt see that one file, so basically the compiler notices that I use the class as a sort of abstract class. Then it makes it into one object and when you call SimpleMenu from menu.h SimpleMenu has all the attributes that menu.cpp made for it.
I hope that right. :)
Yup, in the file 'menu.cpp' in the constructor of class 'SimpleMenu' you're setting all the attributes you want your menu to have ...
Edit:: In menu.h you aren't calling the class 'SimpleMenu', you're only declaring it ...
If your compiler is fully ANSI/ISO compliant it should work with all standard C++ code ...
So does that mean if i renamed the cpp file something apart from menu.cpp it wouldnt work or am i completley on the wrong foot here?
No, it should also work if you rename 'menu.cpp' to something else ...
:)
You can try it !
That's because you're including the file "menu.h" ...
In 'menu.h' the whole class is declared so the compiler knows about it ...
BTW, While compiling the compiler will put all these files together to one file: the object file ...
Some say C# is easier to use with the .net net framework, is that true?
I think that it's only a matter of preference ...
Make use of character escape sequences like the following example:
#include <iostream>
using namespace std;
int main()
{
cout << "The program will be terminated in: ";
for(int i = 5; i > 0; i--)
{
cout << i << " seconds ...";
cout << "\b\b\b\b\b\b\b\b\b\b\b\b\b";
sleep(1000);
}
cout << endl;
return 0;
}
Add the instruction return 0;
just after the for-loop ...
Just ignore my previous post and take a look at the following example:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
vector<string> test(1); /* This vector will contain 1 string */
/* We assign a value to the string */
test[0] = "Ab.d";
/* We print the ASCII code of the first character in the string */
cout << static_cast<int>(test[0][1]) << endl;
/* We check whether the 3rd character of the string is a punct */
if(ispunct(static_cast<int>(test[0][2])))
{
cout << "yes it was a punct" << endl;
}
return 0;
}
That's because the ispunct()
-function is expecting an int as argument, and your vector is of the type string ...
What happens if you use static_cast<int>(_word_list[i])
??
Hope this helps !
Maybe the following article about pointers might help you to understand it better: http://www.cplusplus.com/forum/articles/418/
A pointer is only holding memory addresses ...
Pointers are often used in combination with dynamic memory allocation ...
Lets say you want to create a table of objects, but it depends on the situation where the program is in, you would rather use a pointer to a table of objects (dynamic memory allocation) ...
But when you're always having/needing the same number of objects you can better use the normal declaration ...
Hope this helps !
What I still do not understand is: when you pass a pointer is it not like passing by reference?
Yes, they're both very equal, but there's clearly a difference between them: using a pointer you can change the memory address where the pointer points to, a reference is always pointing to the same memory address, you can't change this ...
BTW, I would like to recommend you to use references as much as you can instead of pointers (that's actually the purpose of why they invented it) ...
Dealing with references is also much simpler and less error-prone than dealing with pointers ...
Also how can I tell if "&" when appearing in the parameters list is reference or "address-of" operator?
It depends on how you're using it, if you're using the &-operator in combination with a pointer then we're talking about the address-operator '&', if you're using it in a function declaration we're talking about the reference-operator '&' ...
Just use a for loop (which runs 5 times) ...
In the while loop you place the instruction sleep(1000);
and you print out the loop index everytime on the screen ...
Something like this:
...
cout << "The program will end in ";
for(int i = 5; i > 0; i--)
{
cout << i << "seconds ..." << endl;
sleep(1000);
}
...
Edit:: I was posting at the same time lerner did ...
Why ?
Consider the following program using #define
:
#include <iostream>
using namespace std;
#define BEGIN 20
#define END 60
#define LENGTH END-BEGIN
int main()
{
cout << "LENGTH = " << LENGTH << endl;
cout << "2*LENGTH = " << 2*LENGTH << endl;
return 0;
}
Well, it doesn't return the result you expected ...
You probably expected it would return 80 ...
You don't have this problem using const
:
#include <iostream>
using namespace std;
int main()
{
const int BEGIN = 20;
const int END = 60;
const int LENGTH = END-BEGIN;
cout << "LENGTH = " << LENGTH << endl;
cout << "2*LENGTH = " << 2*LENGTH << endl;
return 0;
}
Hope this helps !
BTW, const
is invented to avoid the use of #define
, so why would you continue using #define
if you can use a better (and more C++ like instruction) ??
It's maybe better when you change line 11 to: ifstream startnumb;
You shouldn't forget to close the files when you don't need them anymore ...
BTW, on line 7 you're using #define
to declare a constant, it's better to use const
instead of #define
...
Change line 19 to: prime.startnumb >> prime.number;