program is checking for ent when user inputs out?

This is a discussion on program is checking for ent when user inputs out? within the C++ Programming forums, part of the General Programming Boards category; What is wrong with this code? It is fout-ing to the file fine, but when inputing string out, it checks ...

  1. #1
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373

    program is checking for ent when user inputs out?

    What is wrong with this code?

    It is fout-ing to the file fine, but when inputing string out, it checks for ent, so you can't us anything with i, u, b, e, q, d, or c in it, or any spaces. Help!

    Code:
    #include <iostream>
    #include <fstream>
    #include <conio.h>
    #include <string>
    using namespace std;
    char ent;
    char in[100];
    char defi[100];
    char defi2[100];
    char name[100];
    string out;
    char ext[100];
    char open[100];
    char close[100];
    
    int main()
    {
    cout << "Welcome to BDCPP! Name your file:\n";
    cin >> name;
    ofstream fout(name);
    fout <<"//" <<name<<" created in BDCPP\n";
    cout << name << " created\n";
    getch();
    while (ent != 'q')
    {
     system ("cls");
     cout << "Enter:\n";
     cin >> ent;
          if (ent == 'd')
          {
           cout << "Define what?\nEnter:\n";
           cin >> defi;
           cout << "Define "<< defi<<" as:\n";
           cin >> defi2;
           fout << "#define "<<defi<<" " << defi2<< ";\n";
           cout << defi << " defined";
           getch();
          }
          else if (ent == 'c')
          {
           cout << "Char what?\nEnter:\n";
           cin >> in;
           fout << "char "<< in<<";\n";
           cout << in << " chared";
           getch();
          }
          else if (ent =='u')
          {
           cout << "Using namespace std.\n";
           fout << "using namespace std;\n";
           getch();
          }
          else if (ent == 'i')
          {
           cout << "Include what?\nEnter:\n";
           cin >> in;
           fout << "#include <" << in << ">\n";
           cout << in << " included\n";
           getch();
          }
          else if (ent == 'b')
          {
           cout << "Opening int main\n";
           fout << "int main()\n";
           fout << "{\n";
           getch();
          }
          else if (ent == 'o')
          {
           cout << "Output what?\nEnter:\n";
           cin >> out;
           fout << "cout << \"" << out<<"\\n;"<<"\n";
           getch();
          }
          else if (ent == 'e')
          {
           cout << "Closing main()\n";
           fout << "}\n";
           getch();
          }
    }
    }
    Thanks in advanced.
    This war, like the next war, is a war to end war.

  2. #2
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373
    and here's code from the BDCPP program:

    Code:
    //test.cpp created in BDCPP
    #include <iostream>
    char name;
    char name[100];
    int main()
    {
    cout << "Please\n";
    }
    }
    cout << "ur\n";
    }
    This war, like the next war, is a war to end war.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Spell checking program
    By JYorke2097 in forum C Programming
    Replies: 3
    Last Post: 01-15-2009, 07:28 PM
  2. Replies: 7
    Last Post: 08-23-2008, 07:44 AM
  3. Replies: 4
    Last Post: 07-24-2008, 09:02 AM
  4. Replies: 1
    Last Post: 05-19-2006, 08:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21