class-problem

class-problem

Anonymous
Not applicable
615 Views
5 Replies
Message 1 of 6

class-problem

Anonymous
Not applicable
hello,

I created a simple class "Test", with 2 member variables: an integer and
a double. When I want to get the information back from a class member,
the double value always turns out to be 0.
Does anyone know what I do wrong??
(when I do the same in a simple c++ program, it works fine...)

class Test
{
public:
Test() { iVal = 0; \
dVal = 0; }
Test(int newI, double newD) { iVal = newI; \
dVal = newD; }
~Test() {}
void setiVal (int newI) { iVal = newI; }
void setdVal (double newD) { dVal = newD; }
int getiVal () { return iVal; }
double getdVal () { return dVal; }
private:
int iVal;
double dVal;
};


void CreateAndReadTest()
{
Test NewTest(5, 5.8);

acutPrintf("\n *** New Test Parameters ***");
acutPrintf("\n - integer value: %i", ActiveTest.getiVal());
// gives the correct info

acutPrintf("\n - double value: %d", ActiveTest.getdVal());
// always gives zero...

return;
}



--
hold your light, Eleven
0 Likes
616 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
Jeroen,

acutPrintf("\n - double value: %2.4f", ActiveTest.getdVal());
or a whole range of format options the .4 is the number of decimal places.

You should also initialise dVal = 0.0;

Regards Gary,


"Jeroen Henckaerts" wrote in
message news:[email protected]...
> hello,
>
> I created a simple class "Test", with 2 member variables: an integer and
> a double. When I want to get the information back from a class member,
> the double value always turns out to be 0.
> Does anyone know what I do wrong??
> (when I do the same in a simple c++ program, it works fine...)
>
> class Test
> {
> public:
> Test() { iVal = 0; \
> dVal = 0; }
> Test(int newI, double newD) { iVal = newI; \
> dVal = newD; }
> ~Test() {}
> void setiVal (int newI) { iVal = newI; }
> void setdVal (double newD) { dVal = newD; }
> int getiVal () { return iVal; }
> double getdVal () { return dVal; }
> private:
> int iVal;
> double dVal;
> };
>
>
> void CreateAndReadTest()
> {
> Test NewTest(5, 5.8);
>
> acutPrintf("\n *** New Test Parameters ***");
> acutPrintf("\n - integer value: %i", ActiveTest.getiVal());
> // gives the correct info
>
> acutPrintf("\n - double value: %d", ActiveTest.getdVal());
> // always gives zero...
>
> return;
> }
>
>
>
> --
> hold your light, Eleven
0 Likes
Message 3 of 6

Anonymous
Not applicable
"Gary D'Arcy" wrote in
news:[email protected]:

Thanks a lot!
Where can I find these format options??

regards,
jeroen

> Jeroen,
>
> acutPrintf("\n - double value: %2.4f", ActiveTest.getdVal());
> or a whole range of format options the .4 is the number of decimal
> places.
>
> You should also initialise dVal = 0.0;
>
> Regards Gary,
>


--
hold your light, Eleven
0 Likes
Message 4 of 6

Anonymous
Not applicable
Jeroen,

In any C++ book or in the C++ help!

You can format the string prior to output using this option!
e.g.
sprintf("\n%-35s %s %10.2f", temp, comma, total);

Note the "-" for justification!

Have fun!

Gary
www.drcauto.com



"Jeroen Henckaerts" wrote in
message news:[email protected]...
> "Gary D'Arcy" wrote in
> news:[email protected]:
>
> Thanks a lot!
> Where can I find these format options??
>
> regards,
> jeroen
>
> > Jeroen,
> >
> > acutPrintf("\n - double value: %2.4f", ActiveTest.getdVal());
> > or a whole range of format options the .4 is the number of decimal
> > places.
> >
> > You should also initialise dVal = 0.0;
> >
> > Regards Gary,
> >
>
>
> --
> hold your light, Eleven
0 Likes
Message 5 of 6

Anonymous
Not applicable
"Gary D'Arcy" wrote in
news:[email protected]:

Thanks again. 🙂
in a program that's not arx I always use "cout", and so did my c++ course,
that's why I'm not familiar to these notations...

greetz,
jeroen


> Jeroen,
>
> In any C++ book or in the C++ help!
>
> You can format the string prior to output using this option!
> e.g.
> sprintf("\n%-35s %s %10.2f", temp, comma, total);
>
> Note the "-" for justification!
>
> Have fun!
>
> Gary
> www.drcauto.com
>
>

--
hold your light, Eleven
0 Likes
Message 6 of 6

Anonymous
Not applicable
Even A C book will provide the info.


"Gary D'Arcy" wrote in message
news:[email protected]...
> Jeroen,
>
> In any C++ book or in the C++ help!
>
> You can format the string prior to output using this option!
> e.g.
> sprintf("\n%-35s %s %10.2f", temp, comma, total);
>
> Note the "-" for justification!
>
> Have fun!
>
> Gary
> www.drcauto.com
>
>
>
> "Jeroen Henckaerts" wrote in
> message news:[email protected]...
> > "Gary D'Arcy" wrote in
> > news:[email protected]:
> >
> > Thanks a lot!
> > Where can I find these format options??
> >
> > regards,
> > jeroen
> >
> > > Jeroen,
> > >
> > > acutPrintf("\n - double value: %2.4f", ActiveTest.getdVal());
> > > or a whole range of format options the .4 is the number of decimal
> > > places.
> > >
> > > You should also initialise dVal = 0.0;
> > >
> > > Regards Gary,
> > >
> >
> >
> > --
> > hold your light, Eleven
>
>
0 Likes