Sign in to follow this  
m09868

?

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 this post


Link to post
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 this post


Link to post
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

On this page make sure that you

CHECK "Empty Project"

UNCHECK "Precompiled Headers"

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 this post


Link to post
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;

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"

Share this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Orrill
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.


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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this