Can anyone overlook my C++ program and correct me please? (VERY NOOB!!)

Discussion in 'Programming General' started by mstandlee, Nov 7, 2007.

Can anyone overlook my C++ program and correct me please? (VERY NOOB!!)
  1. Unread #1 - Nov 7, 2007 at 4:12 PM
  2. mstandlee
    Joined:
    May 3, 2007
    Posts:
    65
    Referrals:
    0
    Sythe Gold:
    0

    mstandlee Member

    Can anyone overlook my C++ program and correct me please? (VERY NOOB!!)

    Ok. So I got interested in writing C++ after I saw a thread here. I have wanted to know how to program for a while, jus never taken the time to learn it. My programming is still VERY basic, but I would like someone to overlook it and tell me what Im doing wrong. I want it to first not end the program until you press enter. Also, It writes a new text document wether the answer is true or false. Please help me out..

    Code:
    #include <iostream>
    #include <stdio.h> //needed for the fopen command. Writes the txt file
    
    using namespace std;
    
    int main()
    
    {
        
        int yesorno;
    
      cout<<"Would you like to create the file NEWTXTFILE?: "; //this is the test line
      cin>> yesorno;
      cin.ignore(); 
      if (yesorno = true)
      {
       fopen ("newtxtfile.txt", "w+");
       cout<<"The file has been written\n"; //successfully writes a new text file
       cout<<"This program will now close... Press enter to terminate Program.\n";
       cin.get();
          }
      else if (yesorno = false)
     {
      cout<<"The file has not been written and this program will now close\n";
      cout<<"Press enter to terminate Program.\n";
      cin.get();
          }
    }
    
    Thanks to anyone who wouldnt mind taking a look.

    mstandlee
     
  3. Unread #2 - Nov 7, 2007 at 5:43 PM
  4. Resident
    Referrals:
    0

    Resident Guest

    Can anyone overlook my C++ program and correct me please? (VERY NOOB!!)

    For one, you should use the boolean operator == in the if () statement

    ie you're saying if i set yesorno equal to true and it's value is >= 1, then do this, else do this; assuming true holds a value of >= 1, this will always return true, and there can be no chance of the file not being written.

    so if (yesorno == true) (which is really the same as if (yesorno))
    and else if (yesorno == false) (again, the same as if (!yesorno))

    just a start
     
< Green error ? double you tee eff ? | I am new to C++, help? >

Users viewing this thread
1 guest


 
 
Adblock breaks this site