Public Group

?

This topic is 4040 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

ok this is my code // If statements.cpp : Defines the entry point for the console application. #include <iostream> using namespace std; int main() { int age; cout<<"Please input your age: "; cin>> age; cin.ignore(); if ( age < 100 ) { cout<<"You are pretty young!\n"; } else if ( age == 100 ) { cout<<"You are old\n"; } else { cout<<"You are really old\n"; } cin.get(); } #include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { return 0; } as most of you know im new and there are no errors. but when i use the debug feature it doesnt say anything when it is supposed to say an answer. how do i make it show up? i use microsoft visual c++

Share on other sites
Why do you have two main functions?

Share on other sites
one is main and the other is int_main. so i thought there was a difference

Share on other sites
First of all, please choose better names for your topics. A question mark doesn't make a good title.

Secondly, use the [source] [/source] tags to format your code.

And last but not least you seem to have two main functions in your code. Remove the one that contains return 0;

Share on other sites
I'll assume you're using visual studio.

Select File->new->project

Select Win32 Console App and type in a name

A wizard should pop up click next

CHECK "Empty Project"

Then click finish

This should make a project without any of the Visual Studio default stuff

Now select File->new->file

Select C++ file and type in a name.

This will give you a totally empty cpp file.

Type the code you posted in there up until the #include "stdafx.h"

That should work

What I've walked you through is creating a truly empty project. If you aren't careful Visual Studio enables several things that can mess up simple projects like precompiled headers and the unicode/ansi _t macros. A truly empty project should avoid most of those pitfalls

Share on other sites
do i use #include "stdafx.h"?
and now it says it wont be built. there are no error reports though.

my new code

// If statements.cpp : Defines the entry point for the console application.
#include <iostream>

using namespace std;

int main()
{
int age;

cin>> age;
cin.ignore();
if ( age < 100 ) {
cout<<"You are pretty young!\n";
}
else if ( age == 100 ) {
cout<<"You are old\n";
}
else {
cout<<"You are really old\n";
}
cin.get();
}

#include "stdafx.h"

Share on other sites
Everything that begins with '#' is a C preprocessor directive and should placed outside of and before the main() function, usually the first few lines of your code.

#include "stdafx.h"#include <iostream>using namespace std;int main(){    return 0;}

...etc

also I notice in your code you haven't returned 0 at the end of your int main(), it's not vital but it is good c++ practise.

Share on other sites
Quote:
 Original post by Orrillalso I notice in your code you haven't returned 0 at the end of your int main(), it's not vital but it is good c++ practise.

According to the standard main implicitly returns 0 in the absence of any other return statement - so one might consider that the more idiomatic way of doing things in c++

@m09868 If you followed my directions and have an empty project without precompiled headers then DON'T include stdafx.h - it's a precompiled header and you don't want/need it

• 12
• 9
• 13
• 41
• 15