small doubt

Y

yashu21985

Why won't this code compile?
#include <iostream.h>
void Print(int i);
void Print(float f, int skip = 0);
void main()
{
Print(3.3);
}
void Print(int i)
{
cout << "Integer" << endl;
}
void Print(float f, int skip)
{
cout << "Float";
if (skip != 0)
cout << endl;
}
 
J

Johannes Bauer

Why won't this code compile?

Why do you think this code won't copile:

10 PRINT "DUH"
20 PRINT "NOW I KNOW"
30 GOTO 10

Because it's not C, maybe?

Greetings,
Johannes
 
S

santosh

Why won't this code compile?
#include <iostream.h>

This is not C. iostream is C++. Ask in comp.lang.c++
void Print(int i);
void Print(float f, int skip = 0);
void main()

This is illegal in both C and C++. Use int main().
{
Print(3.3);
}
void Print(int i)
{
cout << "Integer" << endl;
}
void Print(float f, int skip)
{
cout << "Float";
if (skip != 0)
cout << endl;
}

Your other problems are C++. Ask in comp.lang.c++
 
R

Richard Heathfield

(e-mail address removed) said:
Why won't this code compile?
#include <iostream.h>

foo.c:1: iostream.h: No such file or directory

I guess that's why.
 
L

loudking

Why do you think this code won't copile:
10 PRINT "DUH"
20 PRINT "NOW I KNOW"
30 GOTO 10

Haha, this reminds me with the happy time with BASIC

I love BASIC more than C !
 
S

santosh

loudking said:
Haha, this reminds me with the happy time with BASIC

I love BASIC more than C !

In a way C has become rather like BASIC has always been. There is an
official ISO Standard that has almost no complete implementations, with
most of the code being written to a de facto Standard or in a mish mash
of various dialects.
 
M

Martin Ambuhl

Why won't this code compile?
#include <iostream.h>
^^^^^^^^^^
Because this is not a standard C (or C++) header?
void Print(int i);
void Print(float f, int skip = 0);
void main()
^^^^
Because main returns an int, and there is no excuse for this Schildtism?
{
Print(3.3);
}
void Print(int i)
{
cout << "Integer" << endl;
^^^^ ^^^^^^^ ^^^^
Because you are app;ying left-shift operators to undefined variables
(cout and endl) and to a string literal ("Integer")?
}
void Print(float f, int skip)
{
cout << "Float";

Because you are attempting to left shift an undefined variable (cout)
by something not an integral scalar?
if (skip != 0)
cout << endl;

Again.

If you cna't figure out what language you are attempting to misuse, then
it is no wonder that you can't write compilable code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top