Hack Forums
[C] What's wrong with this code? (very short code) - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C] What's wrong with this code? (very short code) (/showthread.php?tid=159415)



What's wrong with this code? (very short code) - aquabats - Oct 4, 2009

So I'm trying to learn C++ from this book and it uses an example:

#include <iostream>
using namespace std;

int main()
{
int num = 100;
char letter = 'M';
float decimal = 7.5;
double pi = 3.14159;
bool flag = false;

cout << "num:\t" << num << end1;
cout << "letter\t" << letter << end1;
cout << "decimal:" << decimal << end1;
cout << "precise:" << pi << end1;
cout << "flag\t" << flag << end1;
return 0;
}

now when I try to compile this I get errors;

C:\Documents and Settings\Administrator\Desktop\variables.cpp In function `int main()':

Line 12 C:\Documents and Settings\Administrator\Desktop\variables.cpp `end1' undeclared (first use this function)


I am using Bloodshed Dev-C++

Can anyone help me out?

The outcome is supposed to look like this;

num: 100
letter M
decimal:7.5
precise:3.14159
flag 0


* - Masta of Disasta - Oct 4, 2009

I don't know what's wrong exept: << end1;
It needs to be: << endl; <-- last = L

further i don't know...
will try this evening what's wrong


* - aquabats - Oct 4, 2009

rofl oh

yeah that's the problem

this book made the L look like a 1

thanks man


* - hackfromthegrave - Oct 5, 2009

It's a very common mistake when learning C++.


* - archangel.dmitry - Oct 6, 2009

Also if you declare float, it should be:
Code
float decimal = 7.5f;
If you do not add 'f' compiler "thinks" that 7.5 is type of double, and does automatic casting from double to float, which might cause loose of data.