Compiling problem

Hi all, I'm new to the C++ programming.
I was experimenting with a code provided by a book where I am supposed to show on my screen a table with numbers from 0 to 16 in decimal, hexadecimal and octal
numeration.

I have been over this code for a while now but I can't seem to compile it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream.h>
#include <iomanip.h>

void main () 
{
     //Primeira Linha (Declarações e definições)
     int lastNumber, inc,number;
     //Segunda linha (Afectação de lastNumber)
     lastNumber = 16;
     //Terceira Linha (Afectação de inc)
     inc = 1 ;
     //Quarta Linha (cabeçalho da tela a mostrar)
     cout << "dec\thex\toctal" << endl; //'\t'caractér tab.
     //Quinta Linha (instrução de repetição for)
     for ( number = 0 ;
           number <= lastNumber;
           number = number + inc )
     cout << dec << number << '\t' << hex << number
     << '\t' << oct << number <<endl;
}  


So, I would like to know if it's possible for one of you to please review this code and tell me where I might be wrong please.
Thanks in advance in case you might be able to help me and never mind the comments, they are in Portuguese but I won't mind translating them if it might make my problem easier to solve.
What compiler are you using? I'm using g++ and I can compile it like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <iomanip>

using namespace std;

int main () 
{
     //Primeira Linha (Declarações e definições)
     int lastNumber, inc,number;
     //Segunda linha (Afectação de lastNumber)
     lastNumber = 16;
     //Terceira Linha (Afectação de inc)
     inc = 1 ;
     //Quarta Linha (cabeçalho da tela a mostrar)
     cout << "dec\thex\toctal" << endl; //'\t'caractér tab.
     //Quinta Linha (instrução de repetição for)
     for ( number = 0 ;
           number <= lastNumber;
           number = number + inc )
     cout << dec << number << '\t' << hex << number
     << '\t' << oct << number <<endl;
}  


It compiles for me just fine.
Last edited on
I'm using Dev C++.
Does it compile in the form I posted? I've only used g++

edit: btw, what is the error you get when you try to compile it?
Last edited on
32:2 C:\Dev-Cpp\include\c++\3.4.2\backward\backward_warning.h #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.

5 C:\Documents and Settings\**********.*****-**********\Os meus documentos\Nova pasta (2)\Untitled2.cpp `main' must return `int'


I think you are referring to these messages.

And I also tried to compile the way you coded it and it worked.
Yeah, the difference is that you were using the older style headers for your program. That's what the first warning was about. If it gives you that warning you just have to take off the .h from the end of it (it could only be one of the files out of 5-10 depending on the program so it can be tough to track).

The second error is that main is ALWAYS of the type int, meaning the code is always
int main (*parameters*)
even if you don't want to return anything. It's required by the standard.
I understand now.

Thanks for helping me out with this :)
Topic archived. No new replies allowed.