Thread: Force end

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    7

    Force end

    Is there any way to force a program to shut down without using code to make it crash (or using a while loop)? If the answer is in a tutorial on this site, please tell me which tutorial and I'll find it myself. The reason I want this is to shut down the program when it fails to load a file, preventing the program from screwing up by calling data from a file that doesnt exist, or is corrupted, damaged etc. If there isn't any way to do this please tell me. I'll use the while loop if I have to, but I thought there might be a quicker and easier way to do it.
    EDIT: I have another problem. I just wrote this switch-case bit and Dev C++ is telling my that there are undeclared functions (n, l, and y)

    Code:
     
    cout<<"Would you like to create a new data file or load an existing one.\n";
    cout<<"[N]ew or [L]oad (Capitalized)\n";
    cin>> newload;
    cin.ignore();
    switch ( newload ) {
    case n:
      cout<<"Are you sure? Saved data will be Erased.\n";
      cout<<"[Y]es or [N]o (Capitalized)\n";
      cin>> sure;
      cin.ignore();
        switch ( sure ) {
        case y:
          break;
        case n:
    //This is where i want to put the "End program" statement if I can
          break;
        default:
          break;
        }
      break;
    case l:
      break;
    default:
      break;
    }
    I havent actually put in the code between the case and break sections yet, but as far as I can tell, I don't have any errors in it. I'm also getting a "Warning: Unreachable code at beginning of switch statement" error that I don't understand. I know it's a lot of questions, but I can't find my error, so I need help. Yes, I did check the Switch-Case tutorial but as far as I can tell, I haven't made an error.
    Last edited by Redattack34; 09-06-2005 at 06:00 PM.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    You can use exit to terminate a program. Generally you pass a non-zero error code or EXIT_FAILURE as the parameter.

    You need to put your character literals in single quotes (case 'n': instead of case n:). Also be aware that upper versus lower case will matter.

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    7
    Thanks, but I can't compile my program to see if it worked because of the switch-case problem.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    I edited my post.. add single quotes to the character literals. I don't know if there are any other problems.

  5. #5
    Registered User
    Join Date
    Sep 2005
    Posts
    7
    Thanks. I know the capitalization will matter, I changed them to lowercase in an effort to find out if it was why my code was giving me errors.
    Last edited by Redattack34; 09-06-2005 at 08:05 PM.

  6. #6
    Registered User
    Join Date
    Sep 2005
    Posts
    7
    Now I have another problem After continuing work on my program, and including the namespace std thing to use the setw function, i tried to compile and got all eleven of these:
    In function `int main()':
    case label `'N'' within scope of cleanup or variable array
    warning: destructor needed for `class ofstream a_file'
    warning: where case label appears here
    warning: (enclose actions of previous case statements requiring
    warning: destructors in their own binding contours.)
    jump to case label
    crosses initialization of `class ofstream a_file'
    `default' label within scope of cleanup or variable array
    warning: where case label appears here
    jump to case label
    crosses initialization of `class ofstream a_file'
    `default' label within scope of cleanup or variable array
    warning: destructor needed for `class ifstream b_file'
    warning: where case label appears here
    jump to case label
    crosses initialization of `class ifstream b_file'
    implicit declaration of function `int setw(...)'
    I have never seen any of these errors before, and I can't tell whats causing it because I tried commenting out that new code and it didn't help.

    Here is my code. It's 800 lines long at the moment.

    Code:
    #include <stdio.h>
    #include <iostream>
    #include <fstream>
    #include <stdlib.h>
    #include <windows.h>
    
    using namespace std;
    
    struct Week { //Creates the "Week" Structure
           float Monday; // Variables that can be used within the "Week" Structure
           float Tuesday;
           float Wednesday;
           float Thursday;
           float Friday;
           float Saturday;
           float Sunday;
    };
    
    int main()
    {
    Week One; //Creates the "One" group
      One.Monday = 0; //Assigns values to these variables
      One.Tuesday = 0;
      One.Wednesday = 0;
      One.Thursday = 0;
      One.Friday = 0;
      One.Saturday = 0;
      One.Sunday = 0;
    Week Two;
      Two.Monday = 0;
      Two.Tuesday = 0;
      Two.Wednesday = 0;
      Two.Thursday = 0;
      Two.Friday = 0;
      Two.Saturday = 0;
      Two.Sunday = 0;
    Week Three;
      Three.Monday = 0;
      Three.Tuesday = 0;
      Three.Wednesday = 0;
      Three.Thursday = 0;
      Three.Friday = 0;
      Three.Saturday = 0;
      Three.Sunday = 0;
    Week Four;
      Four.Monday = 0;
      Four.Tuesday = 0;
      Four.Wednesday = 0;
      Four.Thursday = 0;
      Four.Friday = 0;
      Four.Saturday = 0;
      Four.Sunday = 0;
    Week Five;
      Five.Monday = 0;
      Five.Tuesday = 0;
      Five.Wednesday = 0;
      Five.Thursday = 0;
      Five.Friday = 0;
      Five.Saturday = 0;
      Five.Sunday = 0;
    Week Six;
      Six.Monday = 0;
      Six.Tuesday = 0;
      Six.Wednesday = 0;
      Six.Thursday = 0;
      Six.Friday = 0;
      Six.Saturday = 0;
      Six.Sunday = 0;
    Week Seven;
      Seven.Monday = 0;
      Seven.Tuesday = 0;
      Seven.Wednesday = 0;
      Seven.Thursday = 0;
      Seven.Friday = 0;
      Seven.Saturday = 0;
      Seven.Sunday = 0;
    Week Eight;
      Eight.Monday = 0;
      Eight.Tuesday = 0;
      Eight.Wednesday = 0;
      Eight.Thursday = 0;
      Eight.Friday = 0;
      Eight.Saturday = 0;
      Eight.Sunday = 0;
    Week Nine;
      Nine.Monday = 0;
      Nine.Tuesday = 0;
      Nine.Wednesday = 0;
      Nine.Thursday = 0;
      Nine.Friday = 0;
      Nine.Saturday = 0;
      Nine.Sunday = 0;
    Week Ten;
      Ten.Monday = 0;
      Ten.Tuesday = 0;
      Ten.Wednesday = 0;
      Ten.Thursday = 0;
      Ten.Friday = 0;
      Ten.Saturday = 0;
      Ten.Sunday = 0;
    Week Eleven;
      Eleven.Monday = 0;
      Eleven.Tuesday = 0;
      Eleven.Wednesday = 0;
      Eleven.Thursday = 0;
      Eleven.Friday = 0;
      Eleven.Saturday = 0;
      Eleven.Sunday = 0;
    Week Twelve;
      Twelve.Monday = 0;
      Twelve.Tuesday = 0;
      Twelve.Wednesday = 0;
      Twelve.Thursday = 0;
      Twelve.Friday = 0;
      Twelve.Saturday = 0;
      Twelve.Sunday = 0;
    Week Thirteen;
      Thirteen.Monday = 0;
      Thirteen.Tuesday = 0;
      Thirteen.Wednesday = 0;
      Thirteen.Thursday = 0;
      Thirteen.Friday = 0;
      Thirteen.Saturday = 0;
      Thirteen.Sunday = 0;
    Week Fourteen;
      Fourteen.Monday = 0;
      Fourteen.Tuesday = 0;
      Fourteen.Wednesday = 0;
      Fourteen.Thursday = 0;
      Fourteen.Friday = 0;
      Fourteen.Saturday = 0;
      Fourteen.Sunday = 0;
    Week Fifteen;
      Fifteen.Monday = 0;
      Fifteen.Tuesday = 0;
      Fifteen.Wednesday = 0;
      Fifteen.Thursday = 0;
      Fifteen.Friday = 0;
      Fifteen.Saturday = 0;
      Fifteen.Sunday = 0;
    Week Sixteen;
      Sixteen.Monday = 0;
      Sixteen.Tuesday = 0;
      Sixteen.Wednesday = 0;
      Sixteen.Thursday = 0;
      Sixteen.Friday = 0;
      Sixteen.Saturday = 0;
      Sixteen.Sunday = 0;
    Week Seventeen;
      Seventeen.Monday = 0;
      Seventeen.Tuesday = 0;
      Seventeen.Wednesday = 0;
      Seventeen.Thursday = 0;
      Seventeen.Friday = 0;
      Seventeen.Saturday = 0;
      Seventeen.Sunday = 0;
    Week Eighteen;
      Eighteen.Monday = 0;
      Eighteen.Tuesday = 0;
      Eighteen.Wednesday = 0;
      Eighteen.Thursday = 0;
      Eighteen.Friday = 0;
      Eighteen.Saturday = 0;
      Eighteen.Sunday = 0;
    Week Nineteen;
      Nineteen.Monday = 0;
      Nineteen.Tuesday = 0;
      Nineteen.Wednesday = 0;
      Nineteen.Thursday = 0;
      Nineteen.Friday = 0;
      Nineteen.Saturday = 0;
      Nineteen.Sunday = 0;
    Week Twenty;
      Twenty.Monday = 0;
      Twenty.Tuesday = 0;
      Twenty.Wednesday = 0;
      Twenty.Thursday = 0;
      Twenty.Friday = 0;
      Twenty.Saturday = 0;
      Twenty.Sunday = 0;
    Week TwentyOne;
      TwentyOne.Monday = 0;
      TwentyOne.Tuesday = 0;
      TwentyOne.Wednesday = 0;
      TwentyOne.Thursday = 0;
      TwentyOne.Friday = 0;
      TwentyOne.Saturday = 0;
      TwentyOne.Sunday = 0;
    Week TwentyTwo;
      TwentyTwo.Monday = 0;
      TwentyTwo.Tuesday = 0;
      TwentyTwo.Wednesday = 0;
      TwentyTwo.Thursday = 0;
      TwentyTwo.Friday = 0;
      TwentyTwo.Saturday = 0;
      TwentyTwo.Sunday = 0;
    Week TwentyThree;
      TwentyThree.Monday = 0;
      TwentyThree.Tuesday = 0;
      TwentyThree.Wednesday = 0;
      TwentyThree.Thursday = 0;
      TwentyThree.Friday = 0;
      TwentyThree.Saturday = 0;
      TwentyThree.Sunday = 0;
    Week TwentyFour;
      TwentyFour.Monday = 0;
      TwentyFour.Tuesday = 0;
      TwentyFour.Wednesday = 0;
      TwentyFour.Thursday = 0;
      TwentyFour.Friday = 0;
      TwentyFour.Saturday = 0;
      TwentyFour.Sunday = 0;
    Week TwentyFive;
      TwentyFive.Monday = 0;
      TwentyFive.Tuesday = 0;
      TwentyFive.Wednesday = 0;
      TwentyFive.Thursday = 0;
      TwentyFive.Friday = 0;
      TwentyFive.Saturday = 0;
      TwentyFive.Sunday = 0;
    Week TwentySix;
      TwentySix.Monday = 0;
      TwentySix.Tuesday = 0;
      TwentySix.Wednesday = 0;
      TwentySix.Thursday = 0;
      TwentySix.Friday = 0;
      TwentySix.Saturday = 0;
      TwentySix.Sunday = 0;
    Week TwentySeven;
      TwentySeven.Monday = 0;
      TwentySeven.Tuesday = 0;
      TwentySeven.Wednesday = 0;
      TwentySeven.Thursday = 0;
      TwentySeven.Friday = 0;
      TwentySeven.Saturday = 0;
      TwentySeven.Sunday = 0;
    Week TwentyEight;
      TwentyEight.Monday = 0;
      TwentyEight.Tuesday = 0;
      TwentyEight.Wednesday = 0;
      TwentyEight.Thursday = 0;
      TwentyEight.Friday = 0;
      TwentyEight.Saturday = 0;
      TwentyEight.Sunday = 0;
    Week TwentyNine;
      TwentyNine.Monday = 0;
      TwentyNine.Tuesday = 0;
      TwentyNine.Wednesday = 0;
      TwentyNine.Thursday = 0;
      TwentyNine.Friday = 0;
      TwentyNine.Saturday = 0;
      TwentyNine.Sunday = 0;
    Week Thirty;
      Thirty.Monday = 0;
      Thirty.Tuesday = 0;
      Thirty.Wednesday = 0;
      Thirty.Thursday = 0;
      Thirty.Friday = 0;
      Thirty.Saturday = 0;
      Thirty.Sunday = 0;
    Week ThirtyOne;
      ThirtyOne.Monday = 0;
      ThirtyOne.Tuesday = 0;
      ThirtyOne.Wednesday = 0;
      ThirtyOne.Thursday = 0;
      ThirtyOne.Friday = 0;
      ThirtyOne.Saturday = 0;
      ThirtyOne.Sunday = 0;
    Week ThirtyTwo;
      ThirtyTwo.Monday = 0;
      ThirtyTwo.Tuesday = 0;
      ThirtyTwo.Wednesday = 0;
      ThirtyTwo.Thursday = 0;
      ThirtyTwo.Friday = 0;
      ThirtyTwo.Saturday = 0;
      ThirtyTwo.Sunday = 0;
    Week ThirtyThree;
      ThirtyThree.Monday = 0;
      ThirtyThree.Tuesday = 0;
      ThirtyThree.Wednesday = 0;
      ThirtyThree.Thursday = 0;
      ThirtyThree.Friday = 0;
      ThirtyThree.Saturday = 0;
      ThirtyThree.Sunday = 0;
    Week ThirtyFour;
      ThirtyFour.Monday = 0;
      ThirtyFour.Tuesday = 0;
      ThirtyFour.Wednesday = 0;
      ThirtyFour.Thursday = 0;
      ThirtyFour.Friday = 0;
      ThirtyFour.Saturday = 0;
      ThirtyFour.Sunday = 0;
    Week ThirtyFive;
      ThirtyFive.Monday = 0;
      ThirtyFive.Tuesday = 0;
      ThirtyFive.Wednesday = 0;
      ThirtyFive.Thursday = 0;
      ThirtyFive.Friday = 0;
      ThirtyFive.Saturday = 0;
      ThirtyFive.Sunday = 0;
    Week ThirtySix;
      ThirtySix.Monday = 0;
      ThirtySix.Tuesday = 0;
      ThirtySix.Wednesday = 0;
      ThirtySix.Thursday = 0;
      ThirtySix.Friday = 0;
      ThirtySix.Saturday = 0;
      ThirtySix.Sunday = 0;
    Week ThirtySeven;
      ThirtySeven.Monday = 0;
      ThirtySeven.Tuesday = 0;
      ThirtySeven.Wednesday = 0;
      ThirtySeven.Thursday = 0;
      ThirtySeven.Friday = 0;
      ThirtySeven.Saturday = 0;
      ThirtySeven.Sunday = 0;
    Week ThirtyEight;
      ThirtyEight.Monday = 0;
      ThirtyEight.Tuesday = 0;
      ThirtyEight.Wednesday = 0;
      ThirtyEight.Thursday = 0;
      ThirtyEight.Friday = 0;
      ThirtyEight.Saturday = 0;
      ThirtyEight.Sunday = 0;
    Week ThirtyNine;
      ThirtyNine.Monday = 0;
      ThirtyNine.Tuesday = 0;
      ThirtyNine.Wednesday = 0;
      ThirtyNine.Thursday = 0;
      ThirtyNine.Friday = 0;
      ThirtyNine.Saturday = 0;
      ThirtyNine.Sunday = 0;
    Week Forty;
      Forty.Monday = 0;
      Forty.Tuesday = 0;
      Forty.Wednesday = 0;
      Forty.Thursday = 0;
      Forty.Friday = 0;
      Forty.Saturday = 0;
      Forty.Sunday = 0;
    Week FortyOne;
      FortyOne.Monday = 0;
      FortyOne.Tuesday = 0;
      FortyOne.Wednesday = 0;
      FortyOne.Thursday = 0;
      FortyOne.Friday = 0;
      FortyOne.Saturday = 0;
      FortyOne.Sunday = 0;
    Week FortyTwo;
      FortyTwo.Monday = 0;
      FortyTwo.Tuesday = 0;
      FortyTwo.Wednesday = 0;
      FortyTwo.Thursday = 0;
      FortyTwo.Friday = 0;
      FortyTwo.Saturday = 0;
      FortyTwo.Sunday = 0;
    Week FortyThree;
      FortyThree.Monday = 0;
      FortyThree.Tuesday = 0;
      FortyThree.Wednesday = 0;
      FortyThree.Thursday = 0;
      FortyThree.Friday = 0;
      FortyThree.Saturday = 0;
      FortyThree.Sunday = 0;
    Week FortyFour;
      FortyFour.Monday = 0;
      FortyFour.Tuesday = 0;
      FortyFour.Wednesday = 0;
      FortyFour.Thursday = 0;
      FortyFour.Friday = 0;
      FortyFour.Saturday = 0;
      FortyFour.Sunday = 0;
    Week FortyFive;
      FortyFive.Monday = 0;
      FortyFive.Tuesday = 0;
      FortyFive.Wednesday = 0;
      FortyFive.Thursday = 0;
      FortyFive.Friday = 0;
      FortyFive.Saturday = 0;
      FortyFive.Sunday = 0;
    Week FortySix;
      FortySix.Monday = 0;
      FortySix.Tuesday = 0;
      FortySix.Wednesday = 0;
      FortySix.Thursday = 0;
      FortySix.Friday = 0;
      FortySix.Saturday = 0;
      FortySix.Sunday = 0;
    Week FortySeven;
      FortySeven.Monday = 0;
      FortySeven.Tuesday = 0;
      FortySeven.Wednesday = 0;
      FortySeven.Thursday = 0;
      FortySeven.Friday = 0;
      FortySeven.Saturday = 0;
      FortySeven.Sunday = 0;
    Week FortyEight;
      FortyEight.Monday = 0;
      FortyEight.Tuesday = 0;
      FortyEight.Wednesday = 0;
      FortyEight.Thursday = 0;
      FortyEight.Friday = 0;
      FortyEight.Saturday = 0;
      FortyEight.Sunday = 0;
    Week FortyNine;
      FortyNine.Monday = 0;
      FortyNine.Tuesday = 0;
      FortyNine.Wednesday = 0;
      FortyNine.Thursday = 0;
      FortyNine.Friday = 0;
      FortyNine.Saturday = 0;
      FortyNine.Sunday = 0;
    Week Fifty;
      Fifty.Monday = 0;
      Fifty.Tuesday = 0;
      Fifty.Wednesday = 0;
      Fifty.Thursday = 0;
      Fifty.Friday = 0;
      Fifty.Saturday = 0;
      Fifty.Sunday = 0;
    Week FiftyOne;
      FiftyOne.Monday = 0;
      FiftyOne.Tuesday = 0;
      FiftyOne.Wednesday = 0;
      FiftyOne.Thursday = 0;
      FiftyOne.Friday = 0;
      FiftyOne.Saturday = 0;
      FiftyOne.Sunday = 0;
    Week FiftyTwo;
      FiftyTwo.Monday = 0;
      FiftyTwo.Tuesday = 0;
      FiftyTwo.Wednesday = 0;
      FiftyTwo.Thursday = 0;
      FiftyTwo.Friday = 0;
      FiftyTwo.Saturday = 0;
      FiftyTwo.Sunday = 0;
    Week Total;
      Total.Monday = 0;
      Total.Tuesday = 0;
      Total.Wednesday = 0;
      Total.Thursday = 0;
      Total.Friday = 0;
      Total.Saturday = 0;
      Total.Sunday = 0;
    char newload;
    char sure;
    char ok;
    
    cout<<"Would you like to create a new data file or load an existing one.\n";
    cout<<"[N]ew or [L]oad (Capitalized)\n";
    cin>> newload;
    cin.ignore();
    switch ( newload ) {
    case 'N':
      cout<<"Are you sure? Saved data will be Erased.\n";
      cout<<"[Y]es or [N]o (Capitalized)\n";
      cin>> sure;
      cin.ignore();
        switch ( sure ) {
        case 'Y': //If user inputs Y, the program overwrites the stored data with 0's
          ofstream a_file ( "data.txt" ); //Creates a file to store data in
            a_file<< One.Monday << endl << One.Tuesday << endl << One.Wednesday << endl;
            a_file<< One.Thursday << endl << One.Friday << endl << One.Saturday << endl;
            a_file<< One.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< Two.Monday << endl << Two.Tuesday << endl << Two.Wednesday << endl;
            a_file<< Two.Thursday << endl << Two.Friday << endl << Two.Saturday << endl;
            a_file<< Two.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< Three.Monday << endl << Three.Tuesday << endl << Three.Wednesday << endl;
            a_file<< Three.Thursday << endl << Three.Friday << endl << Three.Saturday << endl;
            a_file<< Three.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< Four.Monday << endl << Four.Tuesday << endl << Four.Wednesday << endl;
            a_file<< Four.Thursday << endl << Four.Friday << endl << Four.Saturday << endl;
            a_file<< Four.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< Five.Monday << endl << Five.Tuesday << endl << Five.Wednesday << endl;
            a_file<< Five.Thursday << endl << Five.Friday << endl << Five.Saturday << endl;
            a_file<< Five.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< Six.Monday << endl << Six.Tuesday << endl << Six.Wednesday << endl;
            a_file<< Six.Thursday << endl << Six.Friday << endl << Six.Saturday << endl;
            a_file<< Six.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< Seven.Monday << endl << Seven.Tuesday << endl << Seven.Wednesday << endl;
            a_file<< Seven.Thursday << endl << Seven.Friday << endl << Seven.Saturday << endl;
            a_file<< Seven.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< Eight.Monday << endl << Eight.Tuesday << endl << Eight.Wednesday << endl;
            a_file<< Eight.Thursday << endl << Eight.Friday << endl << Eight.Saturday << endl;
            a_file<< Eight.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< Nine.Monday << endl << Nine.Tuesday << endl << Nine.Wednesday << endl;
            a_file<< Nine.Thursday << endl << Nine.Friday << endl << Nine.Saturday << endl;
            a_file<< Nine.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< Ten.Monday << endl << Ten.Tuesday << endl << Ten.Wednesday << endl;
            a_file<< Ten.Thursday << endl << Ten.Friday << endl << Ten.Saturday << endl;
            a_file<< Ten.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< Eleven.Monday << endl << Eleven.Tuesday << endl << Eleven.Wednesday << endl;
            a_file<< Eleven.Thursday << endl << Eleven.Friday << endl << Eleven.Saturday << endl;
            a_file<< Eleven.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< Twelve.Monday << endl << Twelve.Tuesday << endl << Twelve.Wednesday << endl;
            a_file<< Twelve.Thursday << endl << Twelve.Friday << endl << Twelve.Saturday << endl;
            a_file<< Twelve.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< Thirteen.Monday << endl << Thirteen.Tuesday << endl << Thirteen.Wednesday << endl;
            a_file<< Thirteen.Thursday << endl << Thirteen.Friday << endl << Thirteen.Saturday << endl;
            a_file<< Thirteen.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< Fourteen.Monday << endl << Fourteen.Tuesday << endl << Fourteen.Wednesday << endl;
            a_file<< Fourteen.Thursday << endl << Fourteen.Friday << endl << Fourteen.Saturday << endl;
            a_file<< Fourteen.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< Fifteen.Monday << endl << Fifteen.Tuesday << endl << Fifteen.Wednesday << endl;
            a_file<< Fifteen.Thursday << endl << Fifteen.Friday << endl << Fifteen.Saturday << endl;
            a_file<< Fifteen.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< Sixteen.Monday << endl << Sixteen.Tuesday << endl << Sixteen.Wednesday << endl;
            a_file<< Sixteen.Thursday << endl << Sixteen.Friday << endl << Sixteen.Saturday << endl;
            a_file<< Sixteen.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< Seventeen.Monday << endl << Seventeen.Tuesday << endl << Seventeen.Wednesday << endl;
            a_file<< Seventeen.Thursday << endl << Seventeen.Friday << endl << Seventeen.Saturday << endl;
            a_file<< Seventeen.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< Eighteen.Monday << endl << Eighteen.Tuesday << endl << Eighteen.Wednesday << endl;
            a_file<< Eighteen.Thursday << endl << Eighteen.Friday << endl << Eighteen.Saturday << endl;
            a_file<< Eighteen.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< Nineteen.Monday << endl << Nineteen.Tuesday << endl << Nineteen.Wednesday << endl;
            a_file<< Nineteen.Thursday << endl << Nineteen.Friday << endl << Nineteen.Saturday << endl;
            a_file<< Nineteen.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< Twenty.Monday << endl << Twenty.Tuesday << endl << Twenty.Wednesday << endl;
            a_file<< Twenty.Thursday << endl << Twenty.Friday << endl << Twenty.Saturday << endl;
            a_file<< Twenty.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< TwentyOne.Monday << endl << TwentyOne.Tuesday << endl << TwentyOne.Wednesday << endl;
            a_file<< TwentyOne.Thursday << endl << TwentyOne.Friday << endl << TwentyOne.Saturday << endl;
            a_file<< TwentyOne.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< TwentyTwo.Monday << endl << TwentyTwo.Tuesday << endl << TwentyTwo.Wednesday << endl;
            a_file<< TwentyTwo.Thursday << endl << TwentyTwo.Friday << endl << TwentyTwo.Saturday << endl;
            a_file<< TwentyTwo.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< TwentyThree.Monday << endl << TwentyThree.Tuesday << endl << TwentyThree.Wednesday << endl;
            a_file<< TwentyThree.Thursday << endl << TwentyThree.Friday << endl << TwentyThree.Saturday << endl;
            a_file<< TwentyThree.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< TwentyFour.Monday << endl << TwentyFour.Tuesday << endl << TwentyFour.Wednesday << endl;
            a_file<< TwentyFour.Thursday << endl << TwentyFour.Friday << endl << TwentyFour.Saturday << endl;
            a_file<< TwentyFour.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< TwentyFive.Monday << endl << TwentyFive.Tuesday << endl << TwentyFive.Wednesday << endl;
            a_file<< TwentyFive.Thursday << endl << TwentyFive.Friday << endl << TwentyFive.Saturday << endl;
            a_file<< TwentyFive.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< TwentySix.Monday << endl << TwentySix.Tuesday << endl << TwentySix.Wednesday << endl;
            a_file<< TwentySix.Thursday << endl << TwentySix.Friday << endl << TwentySix.Saturday << endl;
            a_file<< TwentySix.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< TwentySeven.Monday << endl << TwentySeven.Tuesday << endl << TwentySeven.Wednesday << endl;
            a_file<< TwentySeven.Thursday << endl << TwentySeven.Friday << endl << TwentySeven.Saturday << endl;
            a_file<< TwentySeven.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< TwentyEight.Monday << endl << TwentyEight.Tuesday << endl << TwentyEight.Wednesday << endl;
            a_file<< TwentyEight.Thursday << endl << TwentyEight.Friday << endl << TwentyEight.Saturday << endl;
            a_file<< TwentyEight.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< TwentyNine.Monday << endl << TwentyNine.Tuesday << endl << TwentyNine.Wednesday << endl;
            a_file<< TwentyNine.Thursday << endl << TwentyNine.Friday << endl << TwentyNine.Saturday << endl;
            a_file<< TwentyNine.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< Thirty.Monday << endl << Thirty.Tuesday << endl << Thirty.Wednesday << endl;
            a_file<< Thirty.Thursday << endl << Thirty.Friday << endl << Thirty.Saturday << endl;
            a_file<< Thirty.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< ThirtyOne.Monday << endl << ThirtyOne.Tuesday << endl << ThirtyOne.Wednesday << endl;
            a_file<< ThirtyOne.Thursday << endl << ThirtyOne.Friday << endl << ThirtyOne.Saturday << endl;
            a_file<< ThirtyOne.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< ThirtyTwo.Monday << endl << ThirtyTwo.Tuesday << endl << ThirtyTwo.Wednesday << endl;
            a_file<< ThirtyTwo.Thursday << endl << ThirtyTwo.Friday << endl << ThirtyTwo.Saturday << endl;
            a_file<< ThirtyTwo.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< ThirtyThree.Monday << endl << ThirtyThree.Tuesday << endl << ThirtyThree.Wednesday << endl;
            a_file<< ThirtyThree.Thursday << endl << ThirtyThree.Friday << endl << ThirtyThree.Saturday << endl;
            a_file<< ThirtyThree.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< ThirtyFour.Monday << endl << ThirtyFour.Tuesday << endl << ThirtyFour.Wednesday << endl;
            a_file<< ThirtyFour.Thursday << endl << ThirtyFour.Friday << endl << ThirtyFour.Saturday << endl;
            a_file<< ThirtyFour.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< ThirtyFive.Monday << endl << ThirtyFive.Tuesday << endl << ThirtyFive.Wednesday << endl;
            a_file<< ThirtyFive.Thursday << endl << ThirtyFive.Friday << endl << ThirtyFive.Saturday << endl;
            a_file<< ThirtyFive.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< ThirtySix.Monday << endl << ThirtySix.Tuesday << endl << ThirtySix.Wednesday << endl;
            a_file<< ThirtySix.Thursday << endl << ThirtySix.Friday << endl << ThirtySix.Saturday << endl;
            a_file<< ThirtySix.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< ThirtySeven.Monday << endl << ThirtySeven.Tuesday << endl << ThirtySeven.Wednesday << endl;
            a_file<< ThirtySeven.Thursday << endl << ThirtySeven.Friday << endl << ThirtySeven.Saturday << endl;
            a_file<< ThirtySeven.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< ThirtyEight.Monday << endl << ThirtyEight.Tuesday << endl << ThirtyEight.Wednesday << endl;
            a_file<< ThirtyEight.Thursday << endl << ThirtyEight.Friday << endl << ThirtyEight.Saturday << endl;
            a_file<< ThirtyEight.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< ThirtyNine.Monday << endl << ThirtyNine.Tuesday << endl << ThirtyNine.Wednesday << endl;
            a_file<< ThirtyNine.Thursday << endl << ThirtyNine.Friday << endl << ThirtyNine.Saturday << endl;
            a_file<< ThirtyNine.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< Forty.Monday << endl << Forty.Tuesday << endl << Forty.Wednesday << endl;
            a_file<< Forty.Thursday << endl << Forty.Friday << endl << Forty.Saturday << endl;
            a_file<< Forty.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< FortyOne.Monday << endl << FortyOne.Tuesday << endl << FortyOne.Wednesday << endl;
            a_file<< FortyOne.Thursday << endl << FortyOne.Friday << endl << FortyOne.Saturday << endl;
            a_file<< FortyOne.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< FortyTwo.Monday << endl << FortyTwo.Tuesday << endl << FortyTwo.Wednesday << endl;
            a_file<< FortyTwo.Thursday << endl << FortyTwo.Friday << endl << FortyTwo.Saturday << endl;
            a_file<< FortyTwo.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< FortyThree.Monday << endl << FortyThree.Tuesday << endl << FortyThree.Wednesday << endl;
            a_file<< FortyThree.Thursday << endl << FortyThree.Friday << endl << FortyThree.Saturday << endl;
            a_file<< FortyThree.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< FortyFour.Monday << endl << FortyFour.Tuesday << endl << FortyFour.Wednesday << endl;
            a_file<< FortyFour.Thursday << endl << FortyFour.Friday << endl << FortyFour.Saturday << endl;
            a_file<< FortyFour.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< FortyFive.Monday << endl << FortyFive.Tuesday << endl << FortyFive.Wednesday << endl;
            a_file<< FortyFive.Thursday << endl << FortyFive.Friday << endl << FortyFive.Saturday << endl;
            a_file<< FortyFive.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< FortySix.Monday << endl << FortySix.Tuesday << endl << FortySix.Wednesday << endl;
            a_file<< FortySix.Thursday << endl << FortySix.Friday << endl << FortySix.Saturday << endl;
            a_file<< FortySix.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< FortySeven.Monday << endl << FortySeven.Tuesday << endl << FortySeven.Wednesday << endl;
            a_file<< FortySeven.Thursday << endl << FortySeven.Friday << endl << FortySeven.Saturday << endl;
            a_file<< FortySeven.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< FortyEight.Monday << endl << FortyEight.Tuesday << endl << FortyEight.Wednesday << endl;
            a_file<< FortyEight.Thursday << endl << FortyEight.Friday << endl << FortyEight.Saturday << endl;
            a_file<< FortyEight.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< FortyNine.Monday << endl << FortyNine.Tuesday << endl << FortyNine.Wednesday << endl;
            a_file<< FortyNine.Thursday << endl << FortyNine.Friday << endl << FortyNine.Saturday << endl;
            a_file<< FortyNine.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< Fifty.Monday << endl << Fifty.Tuesday << endl << Fifty.Wednesday << endl;
            a_file<< Fifty.Thursday << endl << Fifty.Friday << endl << Fifty.Saturday << endl;
            a_file<< Fifty.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< FiftyOne.Monday << endl << FiftyOne.Tuesday << endl << FiftyOne.Wednesday << endl;
            a_file<< FiftyOne.Thursday << endl << FiftyOne.Friday << endl << FiftyOne.Saturday << endl;
            a_file<< FiftyOne.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file<< FiftyTwo.Monday << endl << FiftyTwo.Tuesday << endl << FiftyTwo.Wednesday << endl;
            a_file<< FiftyTwo.Thursday << endl << FiftyTwo.Friday << endl << FiftyTwo.Saturday << endl;
            a_file<< FiftyTwo.Sunday << endl; // This and two above lines store data from variables in "data.txt"
            a_file.close();//Closes A_file (data.txt)
            cout<<"Please restart the program to use your new file.\n";
            exit(2);
          break;
        case 'N': //If user inputs N, program will end
          cout<<"Ending Program\n";
          cin>> ok;
          exit(2);
          break;
        default: //If user enters a letter that is not accepted, program will end
          cout<<"Incorrect input. Ending Program.\n";
          exit(2);
          break;
        }
      break;
    case 'L': //If user inputs L, the stored data will be loaded and overwrite the 0's that are already assigned
    ifstream b_file ( "data.txt" ); //Creates a file to load data from
            b_file>> One.Monday >> One.Tuesday >> One.Wednesday;
            b_file>> One.Thursday >> One.Friday >> One.Saturday;
            b_file>> One.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> Two.Monday >> Two.Tuesday >> Two.Wednesday;
            b_file>> Two.Thursday >> Two.Friday >> Two.Saturday;
            b_file>> Two.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> Three.Monday >> Three.Tuesday >> Three.Wednesday;
            b_file>> Three.Thursday >> Three.Friday >> Three.Saturday;
            b_file>> Three.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> Four.Monday >> Four.Tuesday >> Four.Wednesday;
            b_file>> Four.Thursday >> Four.Friday >> Four.Saturday;
            b_file>> Four.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> Five.Monday >> Five.Tuesday >> Five.Wednesday;
            b_file>> Five.Thursday >> Five.Friday >> Five.Saturday;
            b_file>> Five.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> Six.Monday >> Six.Tuesday >> Six.Wednesday;
            b_file>> Six.Thursday >> Six.Friday >> Six.Saturday;
            b_file>> Six.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> Seven.Monday >> Seven.Tuesday >> Seven.Wednesday;
            b_file>> Seven.Thursday >> Seven.Friday >> Seven.Saturday;
            b_file>> Seven.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> Eight.Monday >> Eight.Tuesday >> Eight.Wednesday;
            b_file>> Eight.Thursday >> Eight.Friday >> Eight.Saturday;
            b_file>> Eight.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> Nine.Monday >> Nine.Tuesday >> Nine.Wednesday;
            b_file>> Nine.Thursday >> Nine.Friday >> Nine.Saturday;
            b_file>> Nine.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> Ten.Monday >> Ten.Tuesday >> Ten.Wednesday;
            b_file>> Ten.Thursday >> Ten.Friday >> Ten.Saturday;
            b_file>> Ten.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> Eleven.Monday >> Eleven.Tuesday >> Eleven.Wednesday;
            b_file>> Eleven.Thursday >> Eleven.Friday >> Eleven.Saturday;
            b_file>> Eleven.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> Twelve.Monday >> Twelve.Tuesday >> Twelve.Wednesday;
            b_file>> Twelve.Thursday >> Twelve.Friday >> Twelve.Saturday;
            b_file>> Twelve.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> Thirteen.Monday >> Thirteen.Tuesday >> Thirteen.Wednesday;
            b_file>> Thirteen.Thursday >> Thirteen.Friday >> Thirteen.Saturday;
            b_file>> Thirteen.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> Fourteen.Monday >> Fourteen.Tuesday >> Fourteen.Wednesday;
            b_file>> Fourteen.Thursday >> Fourteen.Friday >> Fourteen.Saturday;
            b_file>> Fourteen.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> Fifteen.Monday >> Fifteen.Tuesday >> Fifteen.Wednesday;
            b_file>> Fifteen.Thursday >> Fifteen.Friday >> Fifteen.Saturday;
            b_file>> Fifteen.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> Sixteen.Monday >> Sixteen.Tuesday >> Sixteen.Wednesday;
            b_file>> Sixteen.Thursday >> Sixteen.Friday >> Sixteen.Saturday;
            b_file>> Sixteen.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> Seventeen.Monday >> Seventeen.Tuesday >> Seventeen.Wednesday;
            b_file>> Seventeen.Thursday >> Seventeen.Friday >> Seventeen.Saturday;
            b_file>> Seventeen.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> Eighteen.Monday >> Eighteen.Tuesday >> Eighteen.Wednesday;
            b_file>> Eighteen.Thursday >> Eighteen.Friday >> Eighteen.Saturday;
            b_file>> Eighteen.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> Nineteen.Monday >> Nineteen.Tuesday >> Nineteen.Wednesday;
            b_file>> Nineteen.Thursday >> Nineteen.Friday >> Nineteen.Saturday;
            b_file>> Nineteen.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> Twenty.Monday >> Twenty.Tuesday >> Twenty.Wednesday;
            b_file>> Twenty.Thursday >> Twenty.Friday >> Twenty.Saturday;
            b_file>> Twenty.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> TwentyOne.Monday >> TwentyOne.Tuesday >> TwentyOne.Wednesday;
            b_file>> TwentyOne.Thursday >> TwentyOne.Friday >> TwentyOne.Saturday;
            b_file>> TwentyOne.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> TwentyTwo.Monday >> TwentyTwo.Tuesday >> TwentyTwo.Wednesday;
            b_file>> TwentyTwo.Thursday >> TwentyTwo.Friday >> TwentyTwo.Saturday;
            b_file>> TwentyTwo.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> TwentyThree.Monday >> TwentyThree.Tuesday >> TwentyThree.Wednesday;
            b_file>> TwentyThree.Thursday >> TwentyThree.Friday >> TwentyThree.Saturday;
            b_file>> TwentyThree.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> TwentyFour.Monday >> TwentyFour.Tuesday >> TwentyFour.Wednesday;
            b_file>> TwentyFour.Thursday >> TwentyFour.Friday >> TwentyFour.Saturday;
            b_file>> TwentyFour.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> TwentyFive.Monday >> TwentyFive.Tuesday >> TwentyFive.Wednesday;
            b_file>> TwentyFive.Thursday >> TwentyFive.Friday >> TwentyFive.Saturday;
            b_file>> TwentyFive.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> TwentySix.Monday >> TwentySix.Tuesday >> TwentySix.Wednesday;
            b_file>> TwentySix.Thursday >> TwentySix.Friday >> TwentySix.Saturday;
            b_file>> TwentySix.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> TwentySeven.Monday >> TwentySeven.Tuesday >> TwentySeven.Wednesday;
            b_file>> TwentySeven.Thursday >> TwentySeven.Friday >> TwentySeven.Saturday;
            b_file>> TwentySeven.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> TwentyEight.Monday >> TwentyEight.Tuesday >> TwentyEight.Wednesday;
            b_file>> TwentyEight.Thursday >> TwentyEight.Friday >> TwentyEight.Saturday;
            b_file>> TwentyEight.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> TwentyNine.Monday >> TwentyNine.Tuesday >> TwentyNine.Wednesday;
            b_file>> TwentyNine.Thursday >> TwentyNine.Friday >> TwentyNine.Saturday;
            b_file>> TwentyNine.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> Thirty.Monday >> Thirty.Tuesday >> Thirty.Wednesday;
            b_file>> Thirty.Thursday >> Thirty.Friday >> Thirty.Saturday;
            b_file>> Thirty.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> ThirtyOne.Monday >> ThirtyOne.Tuesday >> ThirtyOne.Wednesday;
            b_file>> ThirtyOne.Thursday >> ThirtyOne.Friday >> ThirtyOne.Saturday;
            b_file>> ThirtyOne.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> ThirtyTwo.Monday >> ThirtyTwo.Tuesday >> ThirtyTwo.Wednesday;
            b_file>> ThirtyTwo.Thursday >> ThirtyTwo.Friday >> ThirtyTwo.Saturday;
            b_file>> ThirtyTwo.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> ThirtyThree.Monday >> ThirtyThree.Tuesday >> ThirtyThree.Wednesday;
            b_file>> ThirtyThree.Thursday >> ThirtyThree.Friday >> ThirtyThree.Saturday;
            b_file>> ThirtyThree.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> ThirtyFour.Monday >> ThirtyFour.Tuesday >> ThirtyFour.Wednesday;
            b_file>> ThirtyFour.Thursday >> ThirtyFour.Friday >> ThirtyFour.Saturday;
            b_file>> ThirtyFour.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> ThirtyFive.Monday >> ThirtyFive.Tuesday >> ThirtyFive.Wednesday;
            b_file>> ThirtyFive.Thursday >> ThirtyFive.Friday >> ThirtyFive.Saturday;
            b_file>> ThirtyFive.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> ThirtySix.Monday >> ThirtySix.Tuesday >> ThirtySix.Wednesday;
            b_file>> ThirtySix.Thursday >> ThirtySix.Friday >> ThirtySix.Saturday;
            b_file>> ThirtySix.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> ThirtySeven.Monday >> ThirtySeven.Tuesday >> ThirtySeven.Wednesday;
            b_file>> ThirtySeven.Thursday >> ThirtySeven.Friday >> ThirtySeven.Saturday;
            b_file>> ThirtySeven.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> ThirtyEight.Monday >> ThirtyEight.Tuesday >> ThirtyEight.Wednesday;
            b_file>> ThirtyEight.Thursday >> ThirtyEight.Friday >> ThirtyEight.Saturday;
            b_file>> ThirtyEight.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> ThirtyNine.Monday >> ThirtyNine.Tuesday >> ThirtyNine.Wednesday;
            b_file>> ThirtyNine.Thursday >> ThirtyNine.Friday >> ThirtyNine.Saturday;
            b_file>> ThirtyNine.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> Forty.Monday >> Forty.Tuesday >> Forty.Wednesday;
            b_file>> Forty.Thursday >> Forty.Friday >> Forty.Saturday;
            b_file>> Forty.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> FortyOne.Monday >> FortyOne.Tuesday >> FortyOne.Wednesday;
            b_file>> FortyOne.Thursday >> FortyOne.Friday >> FortyOne.Saturday;
            b_file>> FortyOne.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> FortyTwo.Monday >> FortyTwo.Tuesday >> FortyTwo.Wednesday;
            b_file>> FortyTwo.Thursday >> FortyTwo.Friday >> FortyTwo.Saturday;
            b_file>> FortyTwo.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> FortyThree.Monday >> FortyThree.Tuesday >> FortyThree.Wednesday;
            b_file>> FortyThree.Thursday >> FortyThree.Friday >> FortyThree.Saturday;
            b_file>> FortyThree.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> FortyFour.Monday >> FortyFour.Tuesday >> FortyFour.Wednesday;
            b_file>> FortyFour.Thursday >> FortyFour.Friday >> FortyFour.Saturday;
            b_file>> FortyFour.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> FortyFive.Monday >> FortyFive.Tuesday >> FortyFive.Wednesday;
            b_file>> FortyFive.Thursday >> FortyFive.Friday >> FortyFive.Saturday;
            b_file>> FortyFive.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> FortySix.Monday >> FortySix.Tuesday >> FortySix.Wednesday;
            b_file>> FortySix.Thursday >> FortySix.Friday >> FortySix.Saturday;
            b_file>> FortySix.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> FortySeven.Monday >> FortySeven.Tuesday >> FortySeven.Wednesday;
            b_file>> FortySeven.Thursday >> FortySeven.Friday >> FortySeven.Saturday;
            b_file>> FortySeven.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> FortyEight.Monday >> FortyEight.Tuesday >> FortyEight.Wednesday;
            b_file>> FortyEight.Thursday >> FortyEight.Friday >> FortyEight.Saturday;
            b_file>> FortyEight.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> FortyNine.Monday >> FortyNine.Tuesday >> FortyNine.Wednesday;
            b_file>> FortyNine.Thursday >> FortyNine.Friday >> FortyNine.Saturday;
            b_file>> FortyNine.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> Fifty.Monday >> Fifty.Tuesday >> Fifty.Wednesday;
            b_file>> Fifty.Thursday >> Fifty.Friday >> Fifty.Saturday;
            b_file>> Fifty.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> FiftyOne.Monday >> FiftyOne.Tuesday >> FiftyOne.Wednesday;
            b_file>> FiftyOne.Thursday >> FiftyOne.Friday >> FiftyOne.Saturday;
            b_file>> FiftyOne.Sunday; // This and two above lines load data from variables in "data.txt"
            b_file>> FiftyTwo.Monday >> FiftyTwo.Tuesday >> FiftyTwo.Wednesday;
            b_file>> FiftyTwo.Thursday >> FiftyTwo.Friday >> FiftyTwo.Saturday;
            b_file>> FiftyTwo.Sunday; // This and two above lines load data from variables in "data.txt"
      break;
    default:
     cout<<"Incorrect input. Ending Program.\n";
     exit(2);
      break;
    cout<< setw(9) << One.Monday << setw(9) << One.Tuesday;
    }
    
    return 0;
    }
    I know I could probably have made it shorter, but I don't especially care. Im using Dev C++ btw.

  7. #7
    Cat Lover
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    109
    Rather than 52 different structs all for the same thing, perhaps you might be better suited by a 2d array.

    So you then get
    Code:
    float Week[52][7]
    So for example this
    Code:
    a_file<< One.Monday << endl << One.Tuesday << endl << One.Wednesday << endl;
            a_file<< One.Thursday << endl << One.Friday << endl << One.Saturday << endl;
            a_file<< One.Sunday << endl;
    Turns into this
    Code:
     for(int n = 0;n<7;n++)
    {
        a_file << Week[0][n] << endl;
    }
    So to dump all your data from all your variables into your file you'd just need
    Code:
    for(int n = 0;n<52;n++)
    {
        for(int i = 0;i<7;i++)
        {
             a_file << Week[n][i] << endl;
        }
    }
    Cuts 156 lines down to 7

    To set all of them to 0
    Code:
    for(int n = 0;n<52;n++)
    {
        for(int i = 0;i<7;i++)
        {
             Week[n][i] = 0;
        }
    }
    And so on.

    *edit*Can't count*
    *edit2* Also, you generally should return 0 on program exit, unless an error occured. So if they chose to end the program, you should return 0.*
    Last edited by Dweia; 09-06-2005 at 08:23 PM.

  8. #8
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Why so much code? Sticking more closely to the idea of OOP, you can vastly reduce the number of lines by overloading the stream insertion and extraction operators (<</>>) and also by providing an appropriate constructor for your struct and using arrays (does the same basic thing as Dweia was saying).

    Code:
    #include <cstdio>
    #include <iostream>
    #include <fstream>
    #include <cstdlib>
    #include <algorithm>  // For copy function
    #include <iterator>
    #include <windows.h>
    
    using namespace std;
    
    struct Week { //Creates the "Week" Structure
        float Monday; // Variables that can be used within the "Week" Structure
        float Tuesday;
        float Wednesday;
        float Thursday;
        float Friday;
        float Saturday;
        float Sunday;
        Week()  // Constructor for the Week struct
        {
            Monday = 0.0f;
            Tuesday = 0.0f;
            Wednesday = 0.0f;
            Thursday = 0.0f;
            Friday = 0.0f;
            Saturday = 0.0f;
            Sunday = 0.0f;
        }
    };
    
    // Stream insertion operator (<<)
    ostream& operator<<(ostream& os,const Week& wk)
    {
        return os << wk.Monday << endl << wk.Tuesday << endl
                  << wk.Wednesday << endl << wk.Thursday << endl
                  << wk.Friday << endl << wk.Saturday << endl
                  << wk.Sunday << endl;
    }
    
    // Stream extraction operator (>>)
    istream& operator>>(istream& is,Week& wk)
    {
        return is >> wk.Monday >> wk.Tuesday >> wk.Wednesday
                  >> wk.Thursday >> wk.Friday >> wk.Saturday
                  >> wk.Sunday;
    }
    
    int main()
    {
        Week weeks[52];  // Create array of 52 Week structs already initialized
        Week Total;
        char newload;
        char sure;
        char ok;
    
        cout<<"Would you like to create a new data file or load an existing one.\n";
        cout<<"[N]ew or [L]oad (Capitalized)\n";
        cin>> newload;
        cin.ignore();
        switch ( newload ) {
            case 'N':
                cout<<"Are you sure? Saved data will be Erased.\n";
                cout<<"[Y]es or [N]o (Capitalized)\n";
                cin>> sure;
                cin.ignore();
                switch ( sure ) {
                    case 'Y': //If user inputs Y, the program overwrites the stored data with 0's
                        ofstream a_file ( "data.txt" ); //Creates a file to store data in
                        // Write data from all 52 Week structs to file
                        copy(weeks,weeks+52,ostream_iterator<Week>(a_file,""));
                        a_file.close();//Closes A_file (data.txt)
                        cout<<"Please restart the program to use your new file.\n";
                        exit(2);
                        break;
                    case 'N': //If user inputs N, program will end
                        cout<<"Ending Program\n";
                        cin>> ok;
                        exit(2);
                        break;
                    default: //If user enters a letter that is not accepted, program will end
                        cout<<"Incorrect input. Ending Program.\n";
                        exit(2);
                        break;
                }
                break;
            case 'L': //If user inputs L, the stored data will be loaded and overwrite the 0's that are already assigned
                ifstream b_file ( "data.txt" ); //Creates a file to load data from
                // Load data for 52 Weeks into 'weeks' array of structs
                copy(istream_iterator<Week>(b_file),istream_iterator<Week>(),weeks);
                b_file.close();
                break;
            default:
                cout<<"Incorrect input. Ending Program.\n";
                exit(2);
                break;
        }
    
        return 0;
    
    }
    See... much less code!
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  9. #9
    Registered User
    Join Date
    Sep 2005
    Posts
    7
    Thanks. I don't know if I will use that. The exact variables and their order is extremely important and I don't understand arrays as well as I would like and I'm not sure I can trust them to do everything correctly. I'm sure thay can, I just don't think I know enough about to do that. It still doesn't help with all of those errors.
    EDIT: To Hk_mp5kpdw: That would be all fine and good but I don't actually understand any of that stuff. I havent actually managed to get that far into the tutorials yet. Anyways, I'm not really looking for ways to shorten my program. My post is about the eleven errors that I don't understand and therefore can't fix.
    Last edited by Redattack34; 09-06-2005 at 09:01 PM.

  10. #10
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Put the code for each case statement inside it's own block. This is necessary when you create variables in that code (like ofstream a_file).
    Code:
    case 'L': //If user inputs L, the stored data will be loaded and overwrite the 0's that are already assigned
    {
       ifstream b_file ( "data.txt" ); //Creates a file to load data from
                b_file>> One.Monday >> One.Tuesday >> One.Wednesday;
                b_file>> One.Thursday >> One.Friday >> One.Saturday;
        // ... <snipped> ...
                b_file>> FiftyTwo.Sunday; // This and two above lines load data from variables in "data.txt"
                break;
    }
    Even if you're not concerned about code size, I'd recommend moving most of that duplicated code out of your program temporarily until you can get the compile errors fixed (just snip the middle part like I did and save it in a separate file for later). This will help you line up your indentations which will help you see where to put the braces.
    Last edited by Daved; 09-06-2005 at 11:23 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Modify to make Doubly Linked List
    By Dampecram in forum C Programming
    Replies: 10
    Last Post: 11-03-2008, 07:25 PM
  2. Adventures in labyrinth generation.
    By guesst in forum Game Programming
    Replies: 8
    Last Post: 10-12-2008, 01:30 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. socket newbie, losing a few chars from server to client
    By registering in forum Linux Programming
    Replies: 2
    Last Post: 06-07-2003, 11:48 AM
  5. Next Question...
    By Azmeos in forum C++ Programming
    Replies: 3
    Last Post: 06-06-2003, 02:40 PM