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. loop help

loop help

Scheduled Pinned Locked Moved C / C++ / MFC
helpiosquestionannouncementlearning
2 Posts 2 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

    I'm trying to make a program that will loop the end where it takes in all the information in the "LIBRARIANSHAVE347CATS.DAT" and if the book has more then 200 pages it outputs the information to a different file called "bigbook.dat" This is my code so far: 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; bool rerun = 1; ifstream infile; ofstream outfilebb; outfile.open("LIBRARIANSHAVE347CATS.DAT",ios::out); while(rerun) { 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; 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"; } 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; } else { cout << "An error occurred while opening the file. \n"; } cout << "Do you want to run this program again? Press 1 if so, 0 if no." << endl; cin >> rerun; //cin.ignore(80, '\n'); } outfile.close(); **infile.open("LIBRARIANSHAVE347CATS.DAT",ios::in); outfilebb.open("Bigbook.dat",ios::app); while(infile) { infile >> books.dewey; infile >> books.title >> endl; infile >> books.author >> endl; infile >> books.released >> endl; infile >> books.num_pages >> endl; infile >> i >> endl; if (books.num_pages > 200) { if(outfilebb) { outfilebb << books.dewey; outfilebb << books.title << endl;**

    D 1 Reply Last reply
    0
    • K klutez123

      I'm trying to make a program that will loop the end where it takes in all the information in the "LIBRARIANSHAVE347CATS.DAT" and if the book has more then 200 pages it outputs the information to a different file called "bigbook.dat" This is my code so far: 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; bool rerun = 1; ifstream infile; ofstream outfilebb; outfile.open("LIBRARIANSHAVE347CATS.DAT",ios::out); while(rerun) { 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; 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"; } 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; } else { cout << "An error occurred while opening the file. \n"; } cout << "Do you want to run this program again? Press 1 if so, 0 if no." << endl; cin >> rerun; //cin.ignore(80, '\n'); } outfile.close(); **infile.open("LIBRARIANSHAVE347CATS.DAT",ios::in); outfilebb.open("Bigbook.dat",ios::app); while(infile) { infile >> books.dewey; infile >> books.title >> endl; infile >> books.author >> endl; infile >> books.released >> endl; infile >> books.num_pages >> endl; infile >> i >> endl; if (books.num_pages > 200) { if(outfilebb) { outfilebb << books.dewey; outfilebb << books.title << endl;**

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

      Ok, so what exactly is the problem?:confused:


      "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
      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