Hey Everone ,

I Wrote a Program To Enter The info and the given info would be saved to a text file .

Here is The Program Itself :

/* Created By Hayzam Sherif 
   Date : 11/7/11'
*/



#include <fstream>
#include <iostream>
#include <cstdlib>

using namespace std;
int main()
{
    char name[100];
    int age;
    char choice[100];
    
    
    cout<<"Name :";
    cin>>name;
    cout<<"Age :";
    cin>>age;
    cout<<name<<"\t"<<age<<" : Should I Save This ?"<<endl;
    if(choice == 'y');
    {
              
              cout<<"OK"<<endl;
              ofstream info;
              info.open ("info.txt");
              info<<name<<age<<endl;
              info.close();
                           }
                           
     else(choice == 'n');
     {
               break;
                 }
     
     else if(choice != 'y' || 'n');
     {
          cout<<"That's Not an option"<<endl;
          break;
          }
    
    
    system("Pause");
    return 0;
    }

I Cannot Understand The Errors xD

Sorry For My Bad English.

#include <fstream>
#include <iostream>
#include <cstdlib>
 
using namespace std;
int main()
{
    char name[100];
    int age;
    char choice[100];
 
 
    cout<<"Name :";
    cin>>name;
    cout<<"Age :";
    cin>>age;
    cout<<name<<"\t"<<age<<" : Should I Save This ? \n (Y/N)"<<endl;
	cin>>choice[0];
    if(choice[0] == 'y')
    {
 
              cout<<"OK"<<endl;
              ofstream info;
              info.open ("info.txt");
              info<<name<<age<<endl;
              info.close();
                           }
 
     else if(choice[0] == 'n')
     {
               exit(0);
                 }
 
     else if(choice[0] != 'y' || 'n')
     {
          cout<<"That's Not an option"<<endl;
          exit(0);
          }
 
 
    system("Pause");
    return 0;
    }

Edited 5 Years Ago by Ezzaral: Added code tags. Please use them to format any code that you post.

without knowing what the errors are (I'm not going to try it myself), here's some things that are immediately clear:
- you're missing several #include directives, starting with iomanip and istream.
- you're comparing the array choice with the character 'y' (this might implicitly work, but is very nasty programming style).
- you have semicolons terminating your if and else statements. This is almost always incorrect.

@jwenting Please Just Give Me a Clean Code Will You? Cuz' I Tried My Best on This Program.BTW No Offence Here :D.

This article has been dead for over six months. Start a new discussion instead.