C++ Error! { missing function header error C2447


// Hello.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <Windows.h>
#include <time.h>
{
using namespace std;
int main();
char response;
cout<<"Hello, I am your computer"<<"\n";
Sleep(2000);
cout<<"I like to take long walks on the beach"<<"\n";
Sleep(2000);
cout<<"These long walks help me clear my mind"<<"\n";
Sleep(2000);
cout<<"Do you like to clear your mind? (Y/N)"<<"\n";
cin<<response"\n";
{
if (response == 'Y');
Yeah me too;
}
{
else if (response == 'N');
You should learn to like it;
}
Sleep(2000);
system ("pause");}
Wow you have messed up quite much....

#include "stdafx.h"
#include <iostream>
#include <Windows.h>
#include <time.h>
{ no need of this bracket
using namespace std;
int main(); you have put a ; here indicating your main has ended
char response;
cout<<"Hello, I am your computer"<<"\n";
Sleep(2000);
cout<<"I like to take long walks on the beach"<<"\n";
Sleep(2000);
cout<<"These long walks help me clear my mind"<<"\n";
Sleep(2000);
cout<<"Do you like to clear your mind? (Y/N)"<<"\n";
cin<<response"\n"; << required before "\n"
{ error causing bracket
if (response == 'Y'); you have put a ; here indicating your if has ended
Yeah me too; missing cout
} error causing bracket
{ error causing bracket
else if (response == 'N'); you have put a ; here indicating your main if ended
You should learn to like it; missing cout
} error causing bracket
Sleep(2000);
system ("pause");} error causing bracket

no value returned in main

If this was your first program you should not jump into C++ like this. Start a tutorial or something from very BEGINNING. You will soon get frustrated otherwise. You can visit http://recurseit.blogspot.com for code snippets and tips...
Last edited on
closed account (EvoTURfi)
You should put using namespace std under #include<time.h>. Also, you need to put int main() at the top. This is why the error is showing up. You need to do this:

1
2
3
4
5
6
7
8
9
#include "stdafx.h"
#include <iostream>
#include <Windows.h>
#include <time.h>
using namespace std;
int main()
{
//  Code goes here...
}


You put your int main() function inside the brackets. This will make the compiler confused on where to start your program!

Also, you are using cin incorrectly. It should be:

cin>>response

Use >> for cin and << for cout

Also on this line:

Yeah me too;

and this line:

You should learn to like it;

You should use cout. Like this:

cout<<"Yeah me too";

Just a tip: You can use endl to insert a new line instead of "\n". Both of them are the same.

As Undeclared said, you are ending many statements with ; which tells the compiler to end that statement!
Last edited on
Topic archived. No new replies allowed.