Go Back   RunUO - Ultima Online Emulation > Developer's Corner > Programming > C/C++

C/C++ C/C++ Discussion

Reply
 
Thread Tools Display Modes
Old 11-25-2006, 03:35 PM   #1 (permalink)
Forum Expert
 
IHaveRegistered's Avatar
 
Join Date: Jun 2003
Location: Ontario
Age: 20
Posts: 4,519
Send a message via MSN to IHaveRegistered
Default Convert.ToInt32()

Hiya, i'm trying to make a little script thingy here, and I can't seem to get Convert.ToInt32() to work. It simply gives me the error(s):

Code:
<filepath here>(49) : error C2065: 'Convert' : undeclared identifier
<filepath here>(49) : error C2228: left of '.ToInt32' must have class/struct/union type
Line 49 is:
Code:
        int hitsmax = Convert.ToInt32((1 / wep[sub].speed) * 3000);
So, at this point the best I can do is:
Code:
        int hitsmax = (int)((1 / wep[sub].speed) * 3000);
which doesn't convert it properly all the time.

What would I have to #include in order to declare Convert.ToInt32?

Thanks!
-Aiden
__________________
IHaveRegistered is offline   Reply With Quote
Old 11-25-2006, 03:50 PM   #2 (permalink)
Master of the Internet
 
Join Date: Oct 2005
Age: 44
Posts: 6,283
Default

try

Code:
System.Convert.ToInt32((1 / wep[sub].speed) * 3000);
or if that still fails, do the calculation first, then convert the result (not sure why that would not work as you have it, though, unless you need another set of parentheses).
Malaperth is offline   Reply With Quote
Old 11-25-2006, 03:54 PM   #3 (permalink)
Forum Expert
 
IHaveRegistered's Avatar
 
Join Date: Jun 2003
Location: Ontario
Age: 20
Posts: 4,519
Send a message via MSN to IHaveRegistered
Default

Quote:
Originally Posted by Malaperth
try

Code:
System.Convert.ToInt32((1 / wep[sub].speed) * 3000);
or if that still fails, do the calculation first, then convert the result (not sure why that would not work as you have it, though, unless you need another set of parentheses).
Nope

Code:
--------------------Configuration: WeaponArmor - Win32 Debug--------------------
Compiling...
WeaponArmor.cpp
C:\Program Files\Microsoft Visual Studio\C++ 6.0\MSDev98\MyProjects\WeaponArmor\WeaponArmor.cpp(50) : error C2065: 'System' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\C++ 6.0\MSDev98\MyProjects\WeaponArmor\WeaponArmor.cpp(50) : error C2228: left of '.Convert' must have class/struct/union type
C:\Program Files\Microsoft Visual Studio\C++ 6.0\MSDev98\MyProjects\WeaponArmor\WeaponArmor.cpp(50) : error C2228: left of '.ToInt32' must have class/struct/union type
Error executing cl.exe.
Creating browse info file...

WeaponArmor.exe - 3 error(s), 0 warning(s)
Another idea I had would be to Floor() them, but I wanted it so it rounds it. (int) doesn't seem to do it properly...


With the calculation done first, the result is the same (good idea though). Tried it as a double and a float. No difference.
__________________
IHaveRegistered is offline   Reply With Quote
Old 11-25-2006, 03:58 PM   #4 (permalink)
Master of the Internet
 
Join Date: Oct 2005
Age: 44
Posts: 6,283
Default

Do you have using System; at the top of the class?
Malaperth is offline   Reply With Quote
Old 11-25-2006, 04:16 PM   #5 (permalink)
Forum Expert
 
IHaveRegistered's Avatar
 
Join Date: Jun 2003
Location: Ontario
Age: 20
Posts: 4,519
Send a message via MSN to IHaveRegistered
Default

Quote:
Originally Posted by Malaperth
Do you have using System; at the top of the class?
Uhh, no... It's using #include's. If I try to do using System; it buggers up still.

Like... so:

Code:
C:\Program Files\Microsoft Visual Studio\C++ 6.0\MSDev98\MyProjects\WeaponArmor\WeaponArmor.cpp(13) : error C2873: 'System' : symbol cannot be used in a using-declaration
Any suggestions on that? I tried to include system (shouldof said that before probably :\), but it gave me this and I was like "huh?"...
__________________
IHaveRegistered is offline   Reply With Quote
Old 11-25-2006, 04:18 PM   #6 (permalink)
Master of the Internet
 
Join Date: Oct 2005
Age: 44
Posts: 6,283
Default

Ok, I'm confused as hell now... I thought 'include' was C++. I guess you'll have to wait for someone smarter than me. Sorry to waste your time. Hmmm... That IS C++, are you trying to write C# or C++?
Malaperth is offline   Reply With Quote
Old 11-25-2006, 04:19 PM   #7 (permalink)
Forum Expert
 
IHaveRegistered's Avatar
 
Join Date: Jun 2003
Location: Ontario
Age: 20
Posts: 4,519
Send a message via MSN to IHaveRegistered
Default

Quote:
Originally Posted by Malaperth
Ok, I'm confused as hell now... I thought 'include' was C++. I guess you'll have to wait for someone smarter than me. Sorry to waste your time.
It is?! Holy crap! XD
__________________
IHaveRegistered is offline   Reply With Quote
Old 11-25-2006, 04:20 PM   #8 (permalink)
Master of the Internet
 
Join Date: Oct 2005
Age: 44
Posts: 6,283
Default

ummm... check this:

Quote:
C:\Program Files\Microsoft Visual Studio\C++ 6.0
Malaperth is offline   Reply With Quote
Old 11-25-2006, 04:25 PM   #9 (permalink)
Forum Expert
 
IHaveRegistered's Avatar
 
Join Date: Jun 2003
Location: Ontario
Age: 20
Posts: 4,519
Send a message via MSN to IHaveRegistered
Default

Quote:
Originally Posted by Malaperth
ummm... check this:
Yea, that's the program i'm using. But I always thought my course was teaching C#... C++ was later on in the course... Though they were similar.

C++ Example
Code:
// Project 1 Cplusplus.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream.h>
#include <conio.h>

int main(void)
{
    cout<<"HEY, you, i'm alive! Oh and Hello C++ World!" << endl;
    getch();
    return 0;
}

C# Example...
Code:
// Project 1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
#include <conio.h>

int main(void)
{
    printf("Hello world!");
    getch();
    return 0;
}
Both of those are actually projects from a scripting course I had (both project 1 obviously... XD). But they're quite similar... The teacher said the first one was in C#, and the second in C++...

Unless he was wrong?
__________________
IHaveRegistered is offline   Reply With Quote
Old 11-25-2006, 04:27 PM   #10 (permalink)
Forum Expert
 
Join Date: Aug 2004
Location: Redmond, WA
Age: 21
Posts: 1,288
Send a message via AIM to Sep102 Send a message via MSN to Sep102
Default

Both are C++.
Sep102 is offline   Reply With Quote
Old 11-25-2006, 04:29 PM   #11 (permalink)
Forum Expert
 
IHaveRegistered's Avatar
 
Join Date: Jun 2003
Location: Ontario
Age: 20
Posts: 4,519
Send a message via MSN to IHaveRegistered
Default

Quote:
Originally Posted by Sep102
Both are C++.
Well I suppose that answers my problem eh? (at least half of it), i've been looking up this code for C#...

Man i'm a retard -_-
__________________
IHaveRegistered is offline   Reply With Quote
Old 11-25-2006, 04:30 PM   #12 (permalink)
Forum Expert
 
Join Date: Jul 2005
Location: Istanbul/Turkey
Age: 27
Posts: 425
Default

the first one is C++, the second is in C.

and what you are trying to do it use .net classes in your C++ code which you cant unless you do it in managed C++ that comes with .NET
__________________
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it."
noobie is offline   Reply With Quote
Old 11-25-2006, 04:31 PM   #13 (permalink)
Master of the Internet
 
Join Date: Oct 2005
Age: 44
Posts: 6,283
Default

Quit that class now. You know more than the teacher
Malaperth is offline   Reply With Quote
Old 11-25-2006, 04:31 PM   #14 (permalink)
Forum Expert
 
Join Date: Aug 2004
Location: Redmond, WA
Age: 21
Posts: 1,288
Send a message via AIM to Sep102 Send a message via MSN to Sep102
Default

Or C++/CLI, Managed C++ is deprecated.
Sep102 is offline   Reply With Quote
Old 11-25-2006, 04:35 PM   #15 (permalink)
Forum Expert
 
IHaveRegistered's Avatar
 
Join Date: Jun 2003
Location: Ontario
Age: 20
Posts: 4,519
Send a message via MSN to IHaveRegistered
Default

Quote:
Originally Posted by Malaperth
Quit that class now. You know more than the teacher
It was a class that I already completed XD lol.

Well, now this is awkward... I'm searching around for a way to get this to work right now, but can't seem to find any sort of #include typeof thing.

Edit:
System::Convert::ToInt32 and System.Convert.ToInt32 give the exact same results... heh...
__________________

Last edited by IHaveRegistered; 11-25-2006 at 04:40 PM.
IHaveRegistered is offline   Reply With Quote
Old 11-25-2006, 04:45 PM   #16 (permalink)
Forum Expert
 
Join Date: Feb 2005
Age: 24
Posts: 985
Send a message via AIM to Nochte
Default

Quote:
Originally Posted by IHaveRegistered
Yea, that's the program i'm using. But I always thought my course was teaching C#... C++ was later on in the course... Though they were similar.

C++ Example
Code:
// Project 1 Cplusplus.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream.h>
#include <conio.h>

int main(void)
{
    cout<<"HEY, you, i'm alive! Oh and Hello C++ World!" << endl;
    getch();
    return 0;
}

C# Example...
Code:
// Project 1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
#include <conio.h>

int main(void)
{
    printf("Hello world!");
    getch();
    return 0;
}
Both of those are actually projects from a scripting course I had (both project 1 obviously... XD). But they're quite similar... The teacher said the first one was in C#, and the second in C++...

Unless he was wrong?

...you're going to have to pm me the name of this "school" and "course" you took so i can go boof somebody. seriously. that shit's funny.
Nochte is offline   Reply With Quote
Old 11-25-2006, 04:45 PM   #17 (permalink)
Forum Expert
 
Join Date: Jul 2005
Location: Istanbul/Turkey
Age: 27
Posts: 425
Default

you might use atoi method. i think prototype was something like:
int atoi (char *)

char * c="5";
int myInt=atoi(c);

or

string c="5";
int myInt=atoi(c.c_str());


you cant use any .NET classes ..

edit:
Nochte: I dont think any teacher would tell something like that. I think Ihavereg. has misunderstood him..
Probably he was saying one of them C and the orher is C++. (although both have cpp extension)
__________________
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it."

Last edited by noobie; 11-25-2006 at 04:50 PM.
noobie is offline   Reply With Quote
Old 11-25-2006, 04:54 PM   #18 (permalink)
Forum Expert
 
IHaveRegistered's Avatar
 
Join Date: Jun 2003
Location: Ontario
Age: 20
Posts: 4,519
Send a message via MSN to IHaveRegistered
Default

atoi converts a string into an integer, i'm mainly trying to convert doubles to integers... I guess i'll give it a shot XD

If you wanna know what schoo, it's Ajax High School. ICS 4M1 is the course.
__________________
IHaveRegistered is offline   Reply With Quote
Old 11-25-2006, 04:58 PM   #19 (permalink)
Forum Expert
 
Join Date: Jul 2005
Location: Istanbul/Turkey
Age: 27
Posts: 425
Default

then use atof
__________________
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it."
noobie is offline   Reply With Quote
Old 11-25-2006, 04:59 PM   #20 (permalink)
Forum Expert
 
IHaveRegistered's Avatar
 
Join Date: Jun 2003
Location: Ontario
Age: 20
Posts: 4,519
Send a message via MSN to IHaveRegistered
Default

Quote:
Originally Posted by noobie
then use atof
That converts a string into a double -_-
__________________
IHaveRegistered is offline   Reply With Quote
Old 11-25-2006, 05:05 PM   #21 (permalink)
Forum Expert
 
Join Date: Jul 2005
Location: Istanbul/Turkey
Age: 27
Posts: 425
Default

yea, i think i need some sleep

just cast it..

int a=(int) myDouble;
__________________
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it."
noobie is offline   Reply With Quote
Old 11-25-2006, 05:06 PM   #22 (permalink)
Forum Expert
 
IHaveRegistered's Avatar
 
Join Date: Jun 2003
Location: Ontario
Age: 20
Posts: 4,519
Send a message via MSN to IHaveRegistered
Default

Quote:
Originally Posted by noobie
yea, i think i need some sleep

just cast it..

int a=(int) myDouble;
Did that, returns a 0.
__________________
IHaveRegistered is offline   Reply With Quote
Old 11-25-2006, 05:19 PM   #23 (permalink)
Forum Expert
 
Join Date: Jul 2005
Location: Istanbul/Turkey
Age: 27
Posts: 425
Default

then its already 0 or 0.xx

thats the simplest way of doing it.
__________________
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it."
noobie is offline   Reply With Quote
Old 11-25-2006, 05:56 PM   #24 (permalink)
Forum Expert
 
IHaveRegistered's Avatar
 
Join Date: Jun 2003
Location: Ontario
Age: 20
Posts: 4,519
Send a message via MSN to IHaveRegistered
Default

Quote:
Originally Posted by noobie
then its already 0 or 0.xx

thats the simplest way of doing it.
Hmm, just checked that. Not true...

It should be 7.65, making it 8.

speed/strreq
37/35
hitsmax = (int)(((1 / speed) * 3000));
maxdamage = (int)(((strreq + speed + hitsmax) / 20));

hitsmax should be 81.08108108... making it 81
It's below 10 appearently, so an If statement makes it 10.

But assuming it WAS 81, then maxdamage should be: 7.65, making it 8.
If it was 0, then it should be: 3.6, making it 4.

Either way, it shouldn't be 0...
__________________
IHaveRegistered is offline   Reply With Quote
Old 11-25-2006, 06:15 PM   #25 (permalink)
Forum Expert
 
Join Date: Aug 2004
Location: Redmond, WA
Age: 21
Posts: 1,288
Send a message via AIM to Sep102 Send a message via MSN to Sep102
Default

Code:
hitsmax = (int)( ((1 / speed) * 3000) + 0.5 );
Casting it to int drops the fractional part of it completely, adding 0.5 to it before doing so rounds properly (i.e. 3.5 rounds to 4, 3.49 rounds to 3).

Last edited by Sep102; 11-25-2006 at 06:17 PM.
Sep102 is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off