Menu

#3 Misstake in example code

open
nobody
None
5
2009-01-02
2009-01-02
No

I am reading through the "PDF Programming with wxDev-C++" bundled with wxDev-C++ 6.10.2.

The book is very helpful, but I think I came across a
mistake. Page 65 of the PDF contains the
TruncationAssignment code:

1 #include <stdio.h>
2 #include <stdlib.h>
3
4 int main(int argc, char *argv[])
5 {
6 short int aShortInt= 0;
7 float aFloat = 536546.64645;
8 long int aLongInt= 2045654297;
9 /*Print the value of the long int*/
10 printf("The long int value is: %d\n",aLongInt);
11 /*Convert the long int to a short int*/
12 aShortInt = aLongInt;
13 printf("The long int has been assigned to a short int\n");
14 /*Print the value of the short int*/
15 printf("The value now = %d\n\n",aShortInt);
16 /*Repeat for a float to int*/
17 printf("The float value is: %f\n",aFloat);
18 printf("The float has now been assigned to a short int\n");
19 printf("The value is now: %d\n",aShortInt);
20 system("PAUSE");
21 return 0;
22 }

It seems like the following line of code should be inserted
between lines 17 and 18:

aShortInt = aFloat;

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.