| www.delorie.com/archives/browse.cgi | search |
| From: | "Ed Fear" <ed AT directxbeginners DOT freeserve DOT co DOT uk> |
| Newsgroups: | comp.os.msdos.djgpp |
| Subject: | Re: Newbie problems... Whats wrong with this code? |
| Date: | Wed, 7 Jul 1999 15:01:49 +0100 |
| Organization: | Customer of Planet Online |
| Lines: | 114 |
| Message-ID: | <7lvmc4$ac5$1@news7.svr.pol.co.uk> |
| References: | <Q4xf3.524$nk6 DOT 2262 AT news1 DOT online DOT no> |
| NNTP-Posting-Host: | modem-103.name51.dialup.pol.co.uk |
| X-Trace: | news7.svr.pol.co.uk 931355844 10629 62.136.185.103 (7 Jul 1999 13:57:24 GMT) |
| NNTP-Posting-Date: | 7 Jul 1999 13:57:24 GMT |
| X-Complaints-To: | abuse AT theplanet DOT net |
| X-Priority: | 3 |
| X-MSMail-Priority: | Normal |
| X-Newsreader: | Microsoft Outlook Express 5.00.2314.1300 |
| X-MimeOLE: | Produced By Microsoft MimeOLE V5.00.2314.1300 |
| To: | djgpp AT delorie DOT com |
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
| Reply-To: | djgpp AT delorie DOT com |
Look below....
Tim Hansen <tmdp AT online DOT no> wrote in message
news:Q4xf3.524$nk6 DOT 2262 AT news1 DOT online DOT no...
> Hi!
> I decided to learn C++ today and I've already got some problems so I hope
> someone could point me in the right direction?
>
> I found a tutorial on the web called 'From the ground up: a guide to c++'
> and sort of got the hang of things so I decided to make up some of my own
> code (based on info I got from here, but my little program was too big for
> the Java C++ compiler so I had to find a real compiler (enough background
> info yet???). I've now installed Djgpp and it seems to be up and running
> fine (I tried out the hello world program in the user manual and that
worked
> like a dream! however...).
>
> Ok, to cut a long story short. I've tested my program. Way to many errors
> though. What I was wondering is wether it is my code that is wrong or if
> I've set up Djgpp wrong? To compile my file I used 'gxx -o test.exe
test.cc'
> the code I've wrote (yeah yeah, I know it's probably crap, you don't need
to
> tell me!) is:
>
You must #include <iostream.h> for cout to work
> void main(void)
>
>
>
> char Venner[2];
> int Alder[2];
> int GjennomsnittAlder;
> char Youngest;
> char Oldest;
>
> Venner[0] = "David";
> Venner[1] = "Stig";
> Venner[2] = "Eirik";
You created an array of char's like this : char Venner[2]. The two elements
in this array are Venner[0] and Venner[1]. Trying to write to Venner[2]
overwrites something in memory - BAD MOVE
Also, a char is ONE letter - NOT A STRING.
> Alder[0] = "21";
> Alder[1] = "28";
> Alder[2] = "26";
To set an int, do it like this:
Alder[0] = 21;
DO NOT WRITE THE SPEECH MARKS
>
> GjennomsnittAlder = (Alder[0] + Alder[1] + Alder[2]) / 3;
>
> if (Alder[0] < Alder[1] && Alder[2])
> Youngest = Venner[0];
> if (Alder[1] < Alder[0] && Alder[2])
> Youngest = Venner[1];
> if (Alder[2] < Alder[0] && Alder[1])
> Youngest = Venner[2];
>
>
> if (Alder[0] > Alder[1] && Alder[2])
> Oldest = Venner[0];
> if (Alder[1] > Alder[0] && Alder[2])
> Oldest = Venner[1];
> if (Alder[2] > Alder[0] && Alder[1])
> Oldest = Venner[0];
>
> switch(Youngest)
> {
> case 'David' : cout << "Hey David is the youngest!" << endl;
> break;
>
> case 'Stig' : cout << "Stig is the youngest???" << endl;
> break;
>
> case 'Eirik' : cout << "Is Eirik really the youngest???" << endl;
> break;
> }
>
> switch(Oldest)
> {
> case 'David' : cout << "David is the oldest???" << endl;
> break;
>
> case 'Stig
> ' : cout << "Are you sure Stig is the oldest?" << endl;
> break;
>
> case 'Eirik' : cout << "Eirik is the Oldest!!!" << endl;
> break;
> }
>
> }
>
> Mostly the error messages say stuff like 'assignment from char to char
lacks
> a cast' and 'character assignment too long' also 'cout' undeclared...
>
> So what am I doing wrong, should I find another tutorial or have I set up
> Djgpp wrong. Thanks for the help (in advance ;-) C'ya!
>
> Tim Hansen.
>
>
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |