0

CODE:

#include <iostream>
#include <cmath>
using namespace std;
//To import packages we use #include.
int integers() {
    //Math operations passed onto cout will automatically calculate itself.
    inum ++;
    dnum --;
    cout << inum << endl;
    //For example, pow()
    cout << pow(2, 6);
    //++ function makes variables increment by 1, -- also does that, reversed.
}

ERROR:

[Running] cd "c:\Users\Administrator\Desktop\C++Workplace\C++Basics\" && g++ NumberUses.cpp -o 
NumberUses && "c:\Users\Administrator\Desktop\C++Workplace\C++Basics\"NumberUses
C:/TDM-GCC-32/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:/TDM-GCC- 
32/bin/../lib/gcc/mingw32/9.2.0/../../../libmingw32.a(main.o):(.text.startup+0xc0): undefined reference 
to `WinMain@16'
collect2.exe: error: ld returned 1 exit status

[Done] exited with code=1 in 0.747 seconds

Is there anything I'm missing out with all those functions? Essentially I'm a newbie and is there any old version confusions between syntax, formatting, etc...?

  • 1
    All C++ programs must have a `main` function that "starts" the program. – NathanOliver Jul 22 '20 at 01:52
  • You are missing at least two things: [why you should never `use namespace std;`](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice), and the fact that every C++ program must have a function with a very special name, see your C++ textbook for more information and examples. – Sam Varshavchik Jul 22 '20 at 01:52
  • You created a UI program, so it needs a [`WinMain()` entry point](https://learn.microsoft.com/en-us/windows/win32/learnwin32/winmain--the-application-entry-point). You don't have one, that is what the linker is complaining about. – Remy Lebeau Jul 22 '20 at 01:58

1 Answers1

1

Your code missing main function, which starts the program;

and

You must declare you variables before use them;

int main() {
    
    int inum = 0, dnum = 0;

    inum++;
    dnum--;
    std::cout << inum << std::endl;
    
    std::cout << std::pow( 2, 6 );
    
}
pvc
  • 1,070
  • 1
  • 9
  • 14