Thread: need help with errors

  1. #1
    mysterious mongoose
    Join Date
    Apr 2005
    Posts
    18

    need help with errors

    My school insists that all work needs to be handed in with a bibliography adn naturally, they insist on using an incredibly complicated method of writing a bibliography, which becomes very time consuming. Im relatively new to C++ and i decided to write a program to make writing bibliographies a bit easier. I have just started writing my program and was testing its first function, which is writing a bibliography for a book. What my program does, is make a html page which contains the bibliography written in the method that my school requires.
    The problem with my program occurs when you use more than one word. e.g. the title contains more than one word. what happens is either, the bibliography is written with each word in the name, as a different part of the bibliography. (Im sorry, that part is a little hard to explain) or, the entire program gets repeated over and over in an endless cycle without stopping even when it reaches a spot where the user should type in something before it continues.
    Anyway, here is my program:


    Code:
    #include <iostream>
    #include <fstream>
    
    using namespace std;
    
    int main()
    {
        string text;
        int choice;
        int finish = 0;
        cout<<"###### ######'s bibliography writing program\n";
        cout<<"A html file will be written containing your bibliography.\n";
        ofstream page("bibliography.html");
        page<<"<html><body><h1><b><u><marquee behavior = 'alternate'>###### ######'s bibliography writing program!!</marquee></u></b></h1>\n";
        while (finish == 0 && finish != 1)
        {
              page<<"<br>";
              cout<<"MENU:\ntype in the number next to want you want to do\n1. Add a book to your bibliography\n2. finish\n";
              cin>>choice;
              if (choice == 1)
              {
                         cout<<"what is the authors last name?\n";
                         cin>>text;
                         page<<text<<", ";
                         cout<<"what is the authors initial?\n";
                         cin>>text;
                         page<<text<<". ";
                         cout<<"what year was it first published in?\n";
                         cin>>text;
                         page<<"("<<text<<"), ";
                         cout<<"what is the book called?\n";
                         cin>>text;
                         page<<"<i>"<<text<<"</i>. ";
                         cout<<"where was it published? If your not sure check the back of the book and covers\n";
                         cin>>text;
                         page<<text<<": ";
                         cout<<"Who is the publisher?\n";
                         cin>>text;
                         page<<text<<".";
              }
              if (choice == 2)
              {
                         finish = 1;
              }
        }
        page<<"</body></html>";
        page.close();
        cout<<"your bibliography is complete, you can now copy and paste or do whatever with the page that has been created\n";
        cin.get();
        cin.get();
    }

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    cin >> stops reading at the first whitespace. Use getline instead.

  3. #3
    mysterious mongoose
    Join Date
    Apr 2005
    Posts
    18
    thank you so much, it was really frustrating me

  4. #4
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    Code:
    #include <iostream>
    #include <fstream>
    
    using namespace std;
    
    int main()
    {
        char text[100];
        char choice[100];
        int finish = 0;
        cout<<"Moongoose's bibliography writing program\n";
        cout<<"A html file will be written containing your bibliography.\n";
        ofstream page("bibliography.html");
        page<<"<html><body><h1><b><marquee behavior = 'alternate'> Moongoose's Bibliography writing program!!</marquee></b></h1>\n";
        int count=1;
        while (finish == 0 && finish != 1)
        {
              page<<"<br>";
              cout<<"MENU:\nType in the number next to want you want to do\n1. Add a book to your bibliography\n2. finish\n";
              cin.getline(choice,100);
              int k=atoi(choice);//Use it to convert to integers
                                 //Or You could just validate the 
                                 //input using a string
              if (k == 1)
              {
                         cout<<"What is the author's last name?\n";
                         cin.getline(text,100);
                         page<<count<<"."<<text<<", ";
                         cout<<"What is the author's initial?\n";
                         cin.getline(text,100);
                         page<<text<<". ";
                         cout<<"What year was it first published in?\n";
                         cin.getline(text,100);
                         page<<"("<<text<<"), ";
                         cout<<"What is the book called?\n";
                         cin.getline(text,100);
                         page<<"<i>"<<text<<"</i>. ";
                         cout<<"Where was it published? If your not sure check the back of the book and covers\n";
                         cin.getline(text,100);
                         page<<text<<": ";
                         cout<<"Who is the publisher?\n";
                         cin.getline(text,100);
                         page<<text<<".";
                         count++;
              }
              if (k == 2)
              {
                         finish = 1;
              }
        }
        page<<"</body></html>";
        page.close();
        cout<<"Your bibliography is complete, you can now copy and paste or do whatever with the page that has been created\n";
        cin.get();
        cin.get();
    }
    I'm not sure if you've already done this but if you're using getline you may encounter problems when reading in ints. This should solve your problem, although there are other ways as well, yada yada yada.

    Last edited by treenef; 07-14-2005 at 01:09 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  2. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  3. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  4. Help me with these errors... :-(
    By major_small in forum C++ Programming
    Replies: 6
    Last Post: 09-07-2003, 08:18 PM
  5. errors in class(urgent)
    By ayesha in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2001, 06:51 PM