Connecting Tech Pros Worldwide Forums | Help | Site Map

ERROR MESSAGES

stanlo
Guest
 
Posts: n/a
#1: Jul 23 '05
Hllo to everyone, this is a folow up of my mathematical expression
assignment.i was tod to do one thing at a time , that i m doing and
have a better derstnding of the whole thing.someone asked me to use
standard libary ,to store my ror messeges instead o arrays. i have a
trial here.please is it a good one, i need your comments.


const char EnterExp = "Please give an expession and press the ENTER
key";

const char result= " The Answer is: ";

const char DivByZero= "WARNING!!!:No Division by Zero;Check answer.";

const char FloatPtNo = "WARNING!!!:No decimal points
allowed,discarded.";


Mike Wahler
Guest
 
Posts: n/a
#2: Jul 23 '05

re: ERROR MESSAGES



"stanlo" <mungwest@yahoo.com> wrote in message
news:1105203759.025956.95820@c13g2000cwb.googlegro ups.com...[color=blue]
> Hllo to everyone, this is a folow up of my mathematical expression
> assignment.[/color]

I'm afraid nobody is going to be able to offer much help
if you don't give the *exact* description of your assignment.
[color=blue]
> i was tod to do one thing at a time , that i m doing and
> have a better derstnding of the whole thing.[/color]

But imo your understanding of C++ is still very lacking.
[color=blue]
>someone asked me to use
> standard libary ,to store my ror messeges instead o arrays. i have a
> trial here.please is it a good one, i need your comments.[/color]

We need a coherent explanation of your assignment.
[color=blue]
>
>
> const char EnterExp = "Please give an expession and press the ENTER
> key";[/color]

This is not valid. You're trying to store a pointer value
into a type 'char' object.
[color=blue]
>
> const char result= " The Answer is: ";[/color]

And again.
[color=blue]
>
> const char DivByZero= "WARNING!!!:No Division by Zero;Check answer.";[/color]

And again.
[color=blue]
>
> const char FloatPtNo = "WARNING!!!:No decimal points
> allowed,discarded.";[/color]

And again.

I think you need to go back and spend some serious time with
your textbook, and try to write some much simpler programs
before you're able to tackle this.



-Mike


Morten Aune Lyrstad
Guest
 
Posts: n/a
#3: Jul 23 '05

re: ERROR MESSAGES


stanlo wrote:[color=blue]
> Hllo to everyone, this is a folow up of my mathematical expression
> assignment.i was tod to do one thing at a time , that i m doing and
> have a better derstnding of the whole thing.someone asked me to use
> standard libary ,to store my ror messeges instead o arrays. i have a
> trial here.please is it a good one, i need your comments.
>
>
> const char EnterExp = "Please give an expession and press the ENTER
> key";
>
> const char result= " The Answer is: ";
>
> const char DivByZero= "WARNING!!!:No Division by Zero;Check answer.";
>
> const char FloatPtNo = "WARNING!!!:No decimal points
> allowed,discarded.";
>[/color]
No, that won't work. You are making variable constants which can only
hold one character.

Use
const char *EnterExp = "Please ...";

Those who suggested you used standard libraries most likely wanted you
to use std::string, which is far, far easier to use than the "const
char*" type string. You can get it by inserting
#include <string>
at the top of your file.
David Harmon
Guest
 
Posts: n/a
#4: Jul 23 '05

re: ERROR MESSAGES


On Sat, 08 Jan 2005 18:15:30 +0100 in comp.lang.c++, Morten Aune
Lyrstad <morten@wantsno.spam> wrote,[color=blue]
>No, that won't work. You are making variable constants which can only
>hold one character.
>
>Use
> const char *EnterExp = "Please ...";[/color]

No need for the gratuitous pointer. Prefer

const char EnterExp[] = "Please ...";

Victor Bazarov
Guest
 
Posts: n/a
#5: Jul 23 '05

re: ERROR MESSAGES


"David Harmon" <source@netcom.com> wrote...[color=blue]
> On Sat, 08 Jan 2005 18:15:30 +0100 in comp.lang.c++, Morten Aune
> Lyrstad <morten@wantsno.spam> wrote,[color=green]
>>No, that won't work. You are making variable constants which can only
>>hold one character.
>>
>>Use
>> const char *EnterExp = "Please ...";[/color]
>
> No need for the gratuitous pointer. Prefer
>
> const char EnterExp[] = "Please ...";
>[/color]

Why? Why did you use the term "gratuitous"? No, I am not trying
to pick a fight. I really want to know. Perhaps you will include
that in your answer, but in case you don't, why prefer an array
over a pointer, if the pointer is never assigned to? Or is it only
to prevent assigning to it?

V


David Harmon
Guest
 
Posts: n/a
#6: Jul 23 '05

re: ERROR MESSAGES


On Sat, 8 Jan 2005 15:28:33 -0500 in comp.lang.c++, "Victor Bazarov"
<v.Abazarov@comAcast.net> wrote,[color=blue][color=green][color=darkred]
>>>Use
>>> const char *EnterExp = "Please ...";[/color]
>>
>> No need for the gratuitous pointer. Prefer
>>
>> const char EnterExp[] = "Please ...";
>>[/color]
>
>Why? Why did you use the term "gratuitous"?[/color]

The pointer occupies an extra sizeof(char *) bytes of memory.
Gratuitous = not being used in any way that adds to the
functionality of the program. As you point out, the pointer is
never assigned to, so why do you need it?

The (char *) has external linkage and the pointer value is not
const, so I suspect that only a heroic optimizer could do anything
to avoid loading it whenever it is used.

On the other hand, the array location is a compile-time constant,
and ought to be accessible from any kind of code with no extra
overhead.

Closed Thread