Thread: Does this look okay? Any changes?

  1. #1
    Unregistered
    Guest

    Post Does this look okay? Any changes?

    // Description: The user will enter a band and the computer will tell
    // the user if the CD is in the library's records or not.

    #include<fstream.h>
    #include<string.h>
    #include<stdlib.h>

    int main()
    {
    // Declare variables
    char band [80];
    char cd_name [80];
    int found;
    ifstream infile;
    found = 0;

    cout << "Sheila Blakely\n";
    cout << "Final 2002\n\n";
    cout << "Music Library";

    //Input from the user
    cout << "Enter a singer or band name: ";
    cin.get(band,80);
    cin.ignore(80, '\n');
    cout << '\n';

    infile.open ("LIBRARY.TXT", ios::in);

    if(infile)
    {
    do
    {
    infile.get(band, 80);
    infile.ignore(80, '\n');
    infile.get(cd_name, 80); infile.ignore (80, '\n');

    if ((strcmp (title, desired_book)) == 0 )
    {
    found = 1;
    break;
    }

    }
    while (found != 1 && !infile.eof());
    }
    else
    {
    "An error occured while opening the file.\n";
    }

    infile.close();
    if (found == 1)
    {
    cout << "The book title that you requested is in our inventory.\n";
    cout << "***CD Information*** \n";
    cout << '\n';
    cout << "CD Title: " << title << '\n';
    cout << "Band/Singer: " << band << '\n';
    }
    else
    {
    cout << "The band or singer you typed in must not be very good\n";
    cout << "we don't waste time with bad music.\n";
    }

    return 0;
    }

  2. #2
    Unregistered
    Guest
    sorry, it should read like this


    // Description: The user will enter a band and the computer will tell
    // the user if the CD is in the library's records or not.

    #include<fstream.h>
    #include<string.h>
    #include<stdlib.h>

    int main()
    {
    // Declare variables
    char band [80];
    char cd_name [80];
    int found;
    ifstream infile;
    found = 0;

    cout << "Sheila Blakely\n";
    cout << "Final 2002\n\n";
    cout << "Music Library";

    //Input from the user
    cout << "Enter a singer or band name: ";
    cin.get(band,80);
    cin.ignore(80, '\n');
    cout << '\n';

    infile.open ("LIBRARY.TXT", ios::in);

    if(infile)
    {
    do
    {
    infile.get(band, 80);
    infile.ignore(80, '\n');
    infile.get(cd_name, 80); infile.ignore (80, '\n');

    if ((strcmp (cd_name, band)) == 0 )
    {
    found = 1;
    break;
    }

    }
    while (found != 1 && !infile.eof());
    }
    else
    {
    "An error occured while opening the file.\n";
    }

    infile.close();
    if (found == 1)
    {
    cout << "The book title that you requested is in our inventory.\n";
    cout << "***CD Information*** \n";
    cout << '\n';
    cout << "CD Title: " << cd_name << '\n';
    cout << "Band/Singer: " << band << '\n';
    }
    else
    {
    cout << "The band or singer you typed in must not be very good\n";
    cout << "we don't waste time with bad music.\n";
    }

    return 0;
    }

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    194
    looks good to me. does it work correctly? i am to lazy right now to compile it, but it looks fine.

    oh and next time use [ CODE ] and [ /CODE ] tags (without the spaces) to make your code look pretty

Popular pages Recent additions subscribe to a feed