Hello Everyone ,

I Have Made a Simple C++ Code And I Get Some Errors I Have Been Trying To Solve this For Like 2-3 Days :(
I am a Beginner in C++

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

using namespace std;
int main()
{
for
char name[100];
int age;
char choice[100];
char cc[100];

cout<<"Name :";
cin>>name;
cout<<"Age :";
cin>>age;
cout<<name<<"\t"<<age<<" : Should I Save This ? \n (Y/N)"<<endl;
cin>>choice[0];
cout<<"Should I Repeat The Program ?"<<endl;
cin>>cc;

if(cc[0] == 'n')
{
     return 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;
}

Well, it first seems like you need your choices inside of a loop, so when you want to repeat, it will actually repeat.
Also, there should be # marks in front of your include statements.
Remove the word "for" from right inside main (or complete a for loop)

I made some minor changes to get it to compile and also some minor cosmetic changes:

#include <fstream>
#include <iostream>
using namespace std;
int main(void)
{
   char name[100]={0};
   int age=0;
   char choice='y';
   char cSaveMe='y';
   ofstream info;
   info.open ("info.txt");

   while('y' == choice)
   {
      cout<<"Name :";
      cin>>name;
      cout<<"Age :";
      cin>>age;
      cout << "Save this data? [y/n] ";
      cin >> cSaveMe;
      if('y' == cSaveMe)
      {
         info<<name<<age<<endl;
         cout << "Saved..." << endl;
      }

      cout << "Repeat this [y/n]? ";
      cin >> choice;
   }

   info.close();
   system("Pause");
   return 0;
}

How Do I Copy This Code ? xD?

How Do I Copy This Code ? xD?

Double click on the code snippet posted

Also, there should be # marks in front of your include statements.

Actually there is a # in his original code it's just that it wasn't indented with four spaces or inside the "Code blocks" so this was interpreted as a heading :)

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.