Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. final loop

final loop

Scheduled Pinned Locked Moved C / C++ / MFC
iosannouncementlearning
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    klutez123
    wrote on last edited by
    #1

    So this is the last loop I need for my project. I need to open the file LIBRARIANSHAVE347CATS.DAT and send the info to the screen. Then, it has to search through all entered data, and create a new output file called "bigbook.dat" in which all entered books of over 200 pages have all their data sent to the new file. So far this is what I have: struct card_catalogue //declare a structure then declare all { //the varibles needed for the struct float dewey; string title; string author; int released; int num_pages; enum typeofbook {fiction = 1, nonfiction, reference, pond}; }; int main() { card_catalogue books; ofstream outfile; int i; cout<< "Enter the Dewey Decimal Number please: "; cin>> books.dewey; cout<< "Enter the Title of the book please: "; getline(cin, books.title); cin.ignore(80, '\n'); cout<< "Enter the Author of the book please: "; getline(cin, books.author); cout<< "Enter the Year of Release please: "; cin>> books.released; cout<< "Enter the Number of Pages please: "; cin>> books.num_pages; cout<< "<-----Type----->"<> i; //books.typeofbook = i; if(i == 1) { cout << "You chose Fiction\n"; } if(i == 2) { cout << "You chose Non-Ficiton\n"; } if(i == 3) { cout << "You chose Reference\n"; } if(i == 4) { cout << "You chose Pond\n"; } outfile.open("LIBRARIANSHAVE347CATS.DAT",ios::app); if(outfile) { outfile << books.dewey; outfile << books.title << endl; outfile << books.author << endl; outfile << books.released << endl; outfile << books.num_pages << endl; outfile << i << endl <

    H D S 3 Replies Last reply
    0
    • K klutez123

      So this is the last loop I need for my project. I need to open the file LIBRARIANSHAVE347CATS.DAT and send the info to the screen. Then, it has to search through all entered data, and create a new output file called "bigbook.dat" in which all entered books of over 200 pages have all their data sent to the new file. So far this is what I have: struct card_catalogue //declare a structure then declare all { //the varibles needed for the struct float dewey; string title; string author; int released; int num_pages; enum typeofbook {fiction = 1, nonfiction, reference, pond}; }; int main() { card_catalogue books; ofstream outfile; int i; cout<< "Enter the Dewey Decimal Number please: "; cin>> books.dewey; cout<< "Enter the Title of the book please: "; getline(cin, books.title); cin.ignore(80, '\n'); cout<< "Enter the Author of the book please: "; getline(cin, books.author); cout<< "Enter the Year of Release please: "; cin>> books.released; cout<< "Enter the Number of Pages please: "; cin>> books.num_pages; cout<< "<-----Type----->"<> i; //books.typeofbook = i; if(i == 1) { cout << "You chose Fiction\n"; } if(i == 2) { cout << "You chose Non-Ficiton\n"; } if(i == 3) { cout << "You chose Reference\n"; } if(i == 4) { cout << "You chose Pond\n"; } outfile.open("LIBRARIANSHAVE347CATS.DAT",ios::app); if(outfile) { outfile << books.dewey; outfile << books.title << endl; outfile << books.author << endl; outfile << books.released << endl; outfile << books.num_pages << endl; outfile << i << endl <

      H Offline
      H Offline
      Hans Dietrich
      wrote on last edited by
      #2

      That looks great, let us know how your project turns out.

      Best wishes, Hans


      [CodeProject Forum Guidelines] [How To Ask A Question] [My Articles]

      1 Reply Last reply
      0
      • K klutez123

        So this is the last loop I need for my project. I need to open the file LIBRARIANSHAVE347CATS.DAT and send the info to the screen. Then, it has to search through all entered data, and create a new output file called "bigbook.dat" in which all entered books of over 200 pages have all their data sent to the new file. So far this is what I have: struct card_catalogue //declare a structure then declare all { //the varibles needed for the struct float dewey; string title; string author; int released; int num_pages; enum typeofbook {fiction = 1, nonfiction, reference, pond}; }; int main() { card_catalogue books; ofstream outfile; int i; cout<< "Enter the Dewey Decimal Number please: "; cin>> books.dewey; cout<< "Enter the Title of the book please: "; getline(cin, books.title); cin.ignore(80, '\n'); cout<< "Enter the Author of the book please: "; getline(cin, books.author); cout<< "Enter the Year of Release please: "; cin>> books.released; cout<< "Enter the Number of Pages please: "; cin>> books.num_pages; cout<< "<-----Type----->"<> i; //books.typeofbook = i; if(i == 1) { cout << "You chose Fiction\n"; } if(i == 2) { cout << "You chose Non-Ficiton\n"; } if(i == 3) { cout << "You chose Reference\n"; } if(i == 4) { cout << "You chose Pond\n"; } outfile.open("LIBRARIANSHAVE347CATS.DAT",ios::app); if(outfile) { outfile << books.dewey; outfile << books.title << endl; outfile << books.author << endl; outfile << books.released << endl; outfile << books.num_pages << endl; outfile << i << endl <

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        klutez123 wrote:

        I need to open the file LIBRARIANSHAVE347CATS.DAT and send the info to the screen.

        So why are you opening the file and writing to it? :confused: Does that not seem the least bit odd to you?

        klutez123 wrote:

        So far this is what I have:

        The code you've shown addresses almost none of your requirements. It allows you to enter data for a single book. You either need to create an array of card_catalogue objects and write out the array after the loop terminates, or you'll need to write out the data in books each iteration of the loop. Where's the loop?


        "A good athlete is the result of a good and worthy opponent." - David Crow

        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

        1 Reply Last reply
        0
        • K klutez123

          So this is the last loop I need for my project. I need to open the file LIBRARIANSHAVE347CATS.DAT and send the info to the screen. Then, it has to search through all entered data, and create a new output file called "bigbook.dat" in which all entered books of over 200 pages have all their data sent to the new file. So far this is what I have: struct card_catalogue //declare a structure then declare all { //the varibles needed for the struct float dewey; string title; string author; int released; int num_pages; enum typeofbook {fiction = 1, nonfiction, reference, pond}; }; int main() { card_catalogue books; ofstream outfile; int i; cout<< "Enter the Dewey Decimal Number please: "; cin>> books.dewey; cout<< "Enter the Title of the book please: "; getline(cin, books.title); cin.ignore(80, '\n'); cout<< "Enter the Author of the book please: "; getline(cin, books.author); cout<< "Enter the Year of Release please: "; cin>> books.released; cout<< "Enter the Number of Pages please: "; cin>> books.num_pages; cout<< "<-----Type----->"<> i; //books.typeofbook = i; if(i == 1) { cout << "You chose Fiction\n"; } if(i == 2) { cout << "You chose Non-Ficiton\n"; } if(i == 3) { cout << "You chose Reference\n"; } if(i == 4) { cout << "You chose Pond\n"; } outfile.open("LIBRARIANSHAVE347CATS.DAT",ios::app); if(outfile) { outfile << books.dewey; outfile << books.title << endl; outfile << books.author << endl; outfile << books.released << endl; outfile << books.num_pages << endl; outfile << i << endl <

          S Offline
          S Offline
          Stephen Hewitt
          wrote on last edited by
          #4

          Ever heard of indentation? I don’t even look at posts in which the poster doesn’t make the effort to indent the code.

          Steve

          N 1 Reply Last reply
          0
          • S Stephen Hewitt

            Ever heard of indentation? I don’t even look at posts in which the poster doesn’t make the effort to indent the code.

            Steve

            N Offline
            N Offline
            Nelek
            wrote on last edited by
            #5

            What does "indent" mean? (I'm spanish :P)

            Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?

            S 1 Reply Last reply
            0
            • N Nelek

              What does "indent" mean? (I'm spanish :P)

              Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?

              S Offline
              S Offline
              Stephen Hewitt
              wrote on last edited by
              #6

              Nelek wrote:

              What does "indent" mean? (I'm spanish)

              In short it means you write this:

              for( ;; )
              {
              // Stuff here...
              }

              instead of this:

              for( ;; )
              {
              // Stuff here...
              }

              Steve

              N 1 Reply Last reply
              0
              • S Stephen Hewitt

                Nelek wrote:

                What does "indent" mean? (I'm spanish)

                In short it means you write this:

                for( ;; )
                {
                // Stuff here...
                }

                instead of this:

                for( ;; )
                {
                // Stuff here...
                }

                Steve

                N Offline
                N Offline
                Nelek
                wrote on last edited by
                #7

                Ok, then it is to use the tabulated structure, isn't it? Thanks for the answer

                Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups