Do you see anything wrong with this if so let me know

#include <iostream>                                                                                      
#include <fstream>    
#include <cstdlib>    
using namespace std;    
 int main ()    
{    
    int num;    
     ifstream AFile;      
     AFile.open('a:\\OddFile.txt');    
     AFile << "Enter an integer number please: ";    
     cin >> num;     
     If (num % 2 = 0)    
            AFile << num << endl;    
     Else    
            AFile << num << endl;    
      system("pause");       
       return 0;    
}

>Do you see anything wrong with this
Yes, I do. Clearly you haven't compiled or run this code, otherwise you would see something wrong as well. I suggest you do that.

i did

this was highlighted as the error

AFile.open('a:\\OddFile.txt');

Yes, that's one of the problems with your program. Good job!

I know but I don't see what the problem with it is, I included the backslashes took out the cin and replaced it with Afile, help me out

and added close. Afile;

>I know but I don't see what the problem with it is
Did you try reading the error? Did you try comparing your other code that does the same thing (opens a file)? Did you try anything? I'm quickly starting to think that you're posting farce threads like this just to screw with us.

Are you trying to help or do you go to everybodys thread and insult them and assume they are not trying, something is wrong with you dude

line 10: Since Afile is an input file you can't use the << operator. So you probably meant to use cout instead of Afile to print the text on the screen.

lines 12 to 15: There is no difference between those conditional statements so you might as well not have the if/else clause at all.

line 14: else is mispelled -- there is no capital E in else.

line 12-15 not need at all?

only line 13 because lines 13 and 15 are identical, so it doesn't matter whether num % 2 is 0 or not.

and line 12 is wrong too because you used the = (assignment) operator instead of the == (boolean) operator.

Narue is attempting to get you to find the errors yourself. All the errors I pointed out (except the lines 12-15 problem) were probably reported by your compiler. Look at the first error, correct it, recompile then repeat this until all errors are fixed. Most compilers will tell you exactly where the errors are. But I must admit that sometimes (ok often) the error messages may be obscure and not tell you very much.

yea thats why I rather have a human being better explain the error messages to me than a bot, because something its not clear.

I see what you are saying about Narue, and I respect that. But he has a rather rude way of going about that which is uncalled for

>Are you trying to help
Yes.

>or do you go to everybodys thread and insult them
Only if they deserve it.

>and assume they are not trying
I see a distinct lack of effort on your part.

>yea thats why I rather have a human being better explain the error messages
You haven't posted any error messages. Thus, nobody can explain them to you. You wanted us to tell you exactly what was wrong with your code and how to fix it, it seems.

whatever dude you are just rude about it and you self proclaiming being the "Expert Meanie" says it all

>>You wanted us to tell you exactly what was wrong with your code and how to fix it, it seems.
I agree -- maybe I should have just kept quiet, but I just can't help myself :)

how about this AD

#include <iostream>                                                                                      
#include <fstream>    
#include <cstdlib>    
using namespace std;    
 int main ()    
{    
    int num;    
     ifstream AFile;      
     AFile.open("a:\\OddFile.txt");    
     cout << "Enter an integer number please: ";    
     AFile >> num;     
     if (num % 2 == 0)    
            cout << num << endl;    
     else    
            cout << num << endl; 
            
           
      system("pause");       
       return 0;    
}

whatever dude you are just rude about it and you self proclaiming being the "Expert Meanie" says it all

Narue isn't a dude. Do you always call women that? And stop the flaming or you'll get hit with a stick and this thread will get closed.

>you are just rude about it
Yes I am. If you don't like it, put me on your ignore list.

>how about this AD
That's much better. However, you're still doing exactly the same thing in both branches of the if..else. Perhaps something more like this:

if ( num % 2 == 0 )
  cout<< num <<" is even\n";
else
  cout<< num <<" is odd\n";

Also, you can compact this:

ifstream AFile;      
AFile.open("a:\\OddFile.txt");

Into this:

ifstream AFile("a:\\OddFile.txt");

Because ifstream has a constructor that does the same thing as open.

how about this AD

what does your compiler tell you?

how am I suppose to know, its a figure of speech, I understand you defending your fellowmod, thats find but lets get back to what this thread is about. I am not flaming Im just hear to get help with my program like everyone else

>>how am I suppose to know, its a figure of speech
You are supposed to compile it then ask questions about what you don't understand. We aren't human compilers you know.

You DO have a computer (yes I know you do or you wouldn't be posting here) and a compiler (yes there are lots of free ones). So failing to do your own compilng is a very poor excuse.

LOL AD when I said "how am I suppose to Know, its a figure of speech" I was talking about the fact that you said I called Narue a Dude when she is a female, and I said "how iam suppose to know"

I think Iam always being misunderstood on here, lets get back to the issues

LOL AD when I said "how am I suppose to Know, its a figure of speech" I was talking about the fact that you said I called Narue a Dude when she is a female, and I said "how iam suppose to know"

I think Iam always being misunderstood on here, lets get back to the issues

Oh I see, sorry for the misunderstanding (generation gap I suppose). You can get a hint by her avatar -- it is wearing a dress. But that doesn't mean much either nowdays :)

yea its a cool avatar but I don't read much into those, but um thanks for the help guys and girls lol

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.