Why won't this C++ program compile?

Started by DeltaEpsilon, April 19, 2016, 07:15:12 PM

Previous topic - Next topic

DeltaEpsilon

Quote#include <iostream>
using namespace std;

bool accept()

{
cout << "Do you want to proceed (y or n)?\n"; // write question
char answer = 0;
cin >> answer; // read answer
if (answer == 'y') return true;
return false;
}

I am learning to program C++ and I am learning about loops. Why won't this program compile? Here is the error message I am getting:

Quote/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status

If anyone here is fluent in C++ I would appreciate help.
The fireworks in my head don't ever seem to stop

DeltaEpsilon

I thought I identified the problem, I saved it with .cpp rather than .cc. I tried to compile it again and got,

Quote/usr/lib/gcc/x86_64-redhat-linux/5.3.1/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
The fireworks in my head don't ever seem to stop

Neutron Jack

Every C++ program needs a main() function:

int main() {
    cout << "Hello, world!\n";
    return 0;
}

Baruch

I always liked to use a working example, when I was learning.  Then make lateral modifications to get what my goal was.  That way, all the bits are there for the particular language and compiler and run-time environment.  As soon as it broke, then the last change I made is where the error is.

My first C language experience was negative, because the compiler sucked.  In theory it was supposed to ignore white space, but it didn't.  So I removed all the white space, then put it all back in.  Probably couldn't tell a single space from a one-space tab ;-)
Ha’át’íísh baa naniná?
Azee’ Å,a’ish nanídį́į́h?
Táadoo ánít’iní.
What are you doing?
Are you taking any medications?
Don't do that.

DeltaEpsilon

Quote from: Neutron Jack on April 19, 2016, 10:01:48 PM
Every C++ program needs a main() function:

int main() {
    cout << "Hello, world!\n";
    return 0;
}


Thank you very much, this worked.
The fireworks in my head don't ever seem to stop