3 Replies - 3652 Views - Last Post: 08 November 2001 - 09:25 AM Rate Topic: -----

#1 leapfrog  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 05-November 01

leap frog #2

Posted 06 November 2001 - 11:25 AM

#include <iostream.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iomanip.h>
#include <ctype.h>
#include <string.h>
#include <fstream.h>

void do_again();// all the voids declares and calls my functions void header_title(); void list(char presidents);// passing the parameters for the presidents list void enter_name(); void before(); void after(); char ans[5], num[10], temp, name[13], i, j; char pres[10][25]={"Washington", "Jefferson", //declares all the presidents to be listed later on "Lincoln", "Wilson","Roosevelt", "Truman","Eisenhower","Kennedy", "Reagan", "Bush"}; ofstream outfile; int main () { outfile.open("ivy.txt",ios::out);// opens my outfile file header_title();//main one liner program outfile.close();// closes my outfile return 0; } void header_title()//header title, tell about my program { cout <<" Ivy Luchetti "; outfile <<" Ivy Luchetti "; cout <<" Class: Computer C++, RRHS "; outfile <<" Class: Computer C++, RRHS "; cout <<" Instructor: Mr. H, Block 3 "; outfile <<" Instructor: Mr. H, Block 3 "; cout <<" Program #4 The Presidents game "; outfile <<" Program #4 The Presidents game "; cout <<" Purpose: Determine the Predecessor/Successor "; outfile <<" Purpose: Determine the Predecessor/Successor "; cout <<"+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= "; outfile <<"+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= "; do_again(); } void do_again()//do again loop asks yes or no and directs the user to the proper area of the program { do { cout <<" Would you like to play the presidents game? ";    outfile <<" Would you like to play the presidents game? ";    cout <<" Type yes or no and then press enter ";    outfile <<" Type yes or no and then press enter ";    cin.get (ans,5);    outfile << ans <<endl;    cin .ignore (80,' ');    if ((strcmp(ans,"yes")==0)||(strcmp(ans,"Yes")==0))//string compare allows user to enter yes or no with out a switch statement {list(pres[10][25]);}              if((strcmp(ans,"no")==0)||(strcmp(ans,"No")==0)) {cout <<"Good bye ";    outfile <<"Good bye ";    exit(1);} }while (1); } void list(char presidents)// shows the list of the 10 presidents and passing parameters { cout <<" Here is a list of 10 presidents "; outfile <<" Here is a list of 10 presidents "; for (i=0; i<=10;i++) cout << pres[i]<<endl; outfile << pres[i]<<endl; for (j=0; j<=10; j++) enter_name(); } void enter_name()// asks the user to enter a president { cout <<" Enter a name from the list and then press enter "; outfile <<" Enter a name from the list and then press enter "; cin.get(name,13); outfile << name <<endl; cin.ignore (80,' '); before(); } void before()//displays all the presidents before the user selected president { cout <<" The presidents before your choice are "; outfile <<" The presidents before your choice are "; if (strcmp(name,"Washington")==0) {cout <<" Washington is the 1st President "; outfile <<" Washington is the 1st President ";} else for (i=j; j>=10; j++) cout << pres[j]<<endl; after(); } void after()//displays all the presidents after the user selected president { cout <<" The presidents after your choice are "; outfile <<" The presidents after your choice are "; if (strcmp(name,"Bush")==0) {cout <<" Bush is the last President "; outfile <<" Bush is the last President ";} else for (i=i+1; i<=9; i++) cout << pres[j]<<endl; }


i worked on my for loops but there are still little things wrong with it.The after loop is the one that prints but  it prints every president one at a time in descending numbers like jefferson 4 times Lincoln 3 times and so on until i goes through the whole list then it will exit. The before loop wont do anything unless u enter washington.

(Edited by leapfrog at 5:29 pm on Nov. 6, 2001)


Is This A Good Question/Topic? 0
  • +

Replies To: leap frog #2

#2 supersloth  Icon User is offline

  • serial frotteur - RUDEST MEMBER ON D.I.C.
  • member icon


Reputation: 4503
  • View blog
  • Posts: 28,411
  • Joined: 21-March 01

Re: leap frog #2

Posted 06 November 2001 - 03:03 PM

the before loop with washington, isnt doing anything, cause you dont have any strcmp's or anything telling it what to do if another name is inputed...
Was This Post Helpful? 0
  • +
  • -

#3 blutrane  Icon User is offline

  • 私もクールです

Reputation: 25
  • View blog
  • Posts: 1,934
  • Joined: 17-May 01

Re: leap frog #2

Posted 06 November 2001 - 11:16 PM

exactly what sloth said, you need to check for all the presidents


oh and for effeciency, you don't need to out everything, unless hanosh says so

(Edited by blutrane at 1:19 am on Nov. 7, 2001)

Was This Post Helpful? 0
  • +
  • -

#4 blutrane  Icon User is offline

  • 私もクールです

Reputation: 25
  • View blog
  • Posts: 1,934
  • Joined: 17-May 01

Re: leap frog #2

Posted 08 November 2001 - 09:25 AM

if you want your code fixed click on chat around 9 during any weeknight except mondays
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1