Structs in C++ using prototypes from the beginning

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • joeschnell
    New Member
    • Apr 2007
    • 47

    Structs in C++ using prototypes from the beginning

    First week of the current trimester and we've taken a huge leap from writing little code snippets of loops and switches to writing an entire program, and expecting it to work!
    I, nor anyone else in my class have heard of structs which is our first assignment. I've been pounding away for several days now and it won't compile beyond my struct declaration. Anyone who knows a bit about C++ I would enjoy you pointing out all of the syntax and logical errors in the first dozen lines of what is over 100 lines of code so far on this program. Here is the guideline:

    CIS 247: Programming Assignment #1

    Worth 5 Points Assigned: Week 1 Due: Week 3

    You have contracted with a media company that deals with CDs, books, movies and video games and will be helping them manage inventory for one of the types of media.

    Create a program that will internally store at least eight media items. Use a global (declared above main() ) structure called book, cd, movie or videoGame. Include at least five member variables (select the appropriate data types) to represent different attributes of a media (some examples: pages, cost, runningTime, format, hardcover, genre, …, etc.).
    ● One of them has to be price, because I will have you calculate tax (rate 8.5%) and total cost.
    ● One has to be a char array (C-String) and
    ● One has to be a char that is an abbreviation (such as r for Red). You select anything for the other two.

    In main(), create 6 global month structure variables to represent the six different media items. For example, a structure for a shirt inventory might be:

    struct shirt {
    char size; // S, M, L, X;
    char brand[15]; // uses C-style strings instead of string objects
    bool shortSleeve;
    char color; // for the required switch statement (r=Red, u=Blue, g=Green, w=White, b=Black, y=Yellow)
    double price;
    };

    Note: The above code is an example, not to be used verbatim. Please choose your own set of variable names and data. You may use similar names. The structure can have the variables in any order.

    You can load the data into the structures at the time of declaration, or read from a file.
    struct shirt concert={'M', “Hanes”, true, ‘b’, 12.5}; // this would be shirt number 1
    struct shirt work={'L', “Sears”, false, ‘u’, 21.95}; // this would be shirt number 2

    … // shirt number 7
    … // shirt number 8

    Note: Select only one media type, come up with your own naming for the variables and use your own (unique) data.

    Write a program that will generate a report showing all of the six media items (I'm using shirts instead here). Requirements:

    ● Create a text menu using a switch() block, to ask for media number, or 0 for all of them, or 99 to exit. All other input will result in an error message.
    ● Write one function that accepts media number as an int (1-8) and prints the appropriate media package information (see Sample Output), by passing the appropriate media to the function as a parameter. It will use the switch() statement to display the appropriate color (or whatever you want to use as a coded item),

    I will be using the following key for color of shirt: (r=Red, u=Blue, g=Green, w=White, b=Black, y=Yellow)

    Sample Output - Show output for at least 4 of the 6 items in your inventory
    Shirt Menu

    Please Enter 1-8 to list the shirts
    Please Enter 0 to list all shirts
    Please Enter 99 to end the program
    Selection: 2

    You have chosen to display information on the Sears shirt:
    Size: L
    Long Sleeve
    Color: Blue
    Price: $21.95
    Tax: $ 1.87
    Total Cost: $23.82

    Note that the output will depend upon the type of media (not shirt) and variables that you select.

    Now, I've given a great deal of effort into the code you are going to be looking at so keep in mind 6 months ago I had never stroked one key of code.
    I'm not sure I'm posting this in the right area either, if not someone please direct me to the C++ posting threads please.



    //Assignment One CIS247 Joseph Matzke
    #include <cstdlib>
    #include <iomanip>
    #include <iostream>
    #include <string>
    using namespace std;

    struct movie
    {
    string rating; //G,PG,PG13,R17,X ,XXX
    char title; //Oceans 13, Oceans 12, Oceans 11, Braveheart, Harry Potter, Caligula
    bool releaseDate; //Still in theatre-released
    char language;//English, Spanish, Japanese, Chinese, German, Swaheely
    double cost [2];
    double tax;
    };
    void playMovie (struct movie); //it will not compile beyond here
    int main(void)
    {
    int choice = 0;
    //movie anyMovie; //declaration-creates object?
    struct movie1={"R17", "Oceans 13", true, 'E', 19.99}; //movie number 1
    movie movie2={"R17", "Oceans 12", false, 'E', 9.99};
    movie movie3={"R17", "Oceans 11", false, 'E', 9.99);
    movie movie4={"R17", "Braveheart ", false, 'E', 9.99};
    movie movie5={"PG", "Harry Potter", false, 'E', 9.99};
    movie movie6={"XXX", "Caligula", false, 'S', 1.99};

    system ("pause");
    return 0;
    }

    do
    {
    cout << "Please enter 0 to list all movies" << endl; //makes sense to display the menu for choice
    cout << "Pleae enter 99 to end the program" << endl; //either display the menu or stop the program
    cout << "Selection: ";

    There is a lot more code to this, my switch module, my array, and so on but they do me no good if I can't compile beyond where I've noted.
    I've changed from --void main (void) to--int main()--to int main (void)-- and regardless of what I do, actually my original code did not have a return in the main but the compiler message seemed to want me to return an int. Can anyone spot the problem? Thanks
  • ilikepython
    Recognized Expert Contributor
    • Feb 2007
    • 844

    #2
    Originally posted by joeschnell
    First week of the current trimester and we've taken a huge leap from writing little code snippets of loops and switches to writing an entire program, and expecting it to work!
    I, nor anyone else in my class have heard of structs which is our first assignment. I've been pounding away for several days now and it won't compile beyond my struct declaration. Anyone who knows a bit about C++ I would enjoy you pointing out all of the syntax and logical errors in the first dozen lines of what is over 100 lines of code so far on this program. Here is the guideline:

    CIS 247: Programming Assignment #1

    Worth 5 Points Assigned: Week 1 Due: Week 3

    You have contracted with a media company that deals with CDs, books, movies and video games and will be helping them manage inventory for one of the types of media.

    Create a program that will internally store at least eight media items. Use a global (declared above main() ) structure called book, cd, movie or videoGame. Include at least five member variables (select the appropriate data types) to represent different attributes of a media (some examples: pages, cost, runningTime, format, hardcover, genre, …, etc.).
    ● One of them has to be price, because I will have you calculate tax (rate 8.5%) and total cost.
    ● One has to be a char array (C-String) and
    ● One has to be a char that is an abbreviation (such as r for Red). You select anything for the other two.

    In main(), create 6 global month structure variables to represent the six different media items. For example, a structure for a shirt inventory might be:

    struct shirt {
    char size; // S, M, L, X;
    char brand[15]; // uses C-style strings instead of string objects
    bool shortSleeve;
    char color; // for the required switch statement (r=Red, u=Blue, g=Green, w=White, b=Black, y=Yellow)
    double price;
    };

    Note: The above code is an example, not to be used verbatim. Please choose your own set of variable names and data. You may use similar names. The structure can have the variables in any order.

    You can load the data into the structures at the time of declaration, or read from a file.
    struct shirt concert={'M', “Hanes”, true, ‘b’, 12.5}; // this would be shirt number 1
    struct shirt work={'L', “Sears”, false, ‘u’, 21.95}; // this would be shirt number 2

    … // shirt number 7
    … // shirt number 8

    Note: Select only one media type, come up with your own naming for the variables and use your own (unique) data.

    Write a program that will generate a report showing all of the six media items (I'm using shirts instead here). Requirements:

    ● Create a text menu using a switch() block, to ask for media number, or 0 for all of them, or 99 to exit. All other input will result in an error message.
    ● Write one function that accepts media number as an int (1-8) and prints the appropriate media package information (see Sample Output), by passing the appropriate media to the function as a parameter. It will use the switch() statement to display the appropriate color (or whatever you want to use as a coded item),

    I will be using the following key for color of shirt: (r=Red, u=Blue, g=Green, w=White, b=Black, y=Yellow)

    Sample Output - Show output for at least 4 of the 6 items in your inventory
    Shirt Menu

    Please Enter 1-8 to list the shirts
    Please Enter 0 to list all shirts
    Please Enter 99 to end the program
    Selection: 2

    You have chosen to display information on the Sears shirt:
    Size: L
    Long Sleeve
    Color: Blue
    Price: $21.95
    Tax: $ 1.87
    Total Cost: $23.82

    Note that the output will depend upon the type of media (not shirt) and variables that you select.

    Now, I've given a great deal of effort into the code you are going to be looking at so keep in mind 6 months ago I had never stroked one key of code.
    I'm not sure I'm posting this in the right area either, if not someone please direct me to the C++ posting threads please.



    //Assignment One CIS247 Joseph Matzke
    #include <cstdlib>
    #include <iomanip>
    #include <iostream>
    #include <string>
    using namespace std;

    struct movie
    {
    string rating; //G,PG,PG13,R17,X ,XXX
    char title; //Oceans 13, Oceans 12, Oceans 11, Braveheart, Harry Potter, Caligula
    bool releaseDate; //Still in theatre-released
    char language;//English, Spanish, Japanese, Chinese, German, Swaheely
    double cost [2];
    double tax;
    };
    void playMovie (struct movie); //it will not compile beyond here
    int main(void)
    {
    int choice = 0;
    //movie anyMovie; //declaration-creates object?
    struct movie1={"R17", "Oceans 13", true, 'E', 19.99}; //movie number 1
    movie movie2={"R17", "Oceans 12", false, 'E', 9.99};
    movie movie3={"R17", "Oceans 11", false, 'E', 9.99);
    movie movie4={"R17", "Braveheart ", false, 'E', 9.99};
    movie movie5={"PG", "Harry Potter", false, 'E', 9.99};
    movie movie6={"XXX", "Caligula", false, 'S', 1.99};

    system ("pause");
    return 0;
    }

    do
    {
    cout << "Please enter 0 to list all movies" << endl; //makes sense to display the menu for choice
    cout << "Pleae enter 99 to end the program" << endl; //either display the menu or stop the program
    cout << "Selection: ";

    There is a lot more code to this, my switch module, my array, and so on but they do me no good if I can't compile beyond where I've noted.
    I've changed from --void main (void) to--int main()--to int main (void)-- and regardless of what I do, actually my original code did not have a return in the main but the compiler message seemed to want me to return an int. Can anyone spot the problem? Thanks
    Try making the prototype this:
    [code=cpp]
    void playMovie(movie movie_a);
    [/code]
    And also in your struct you have title and language as a char, which means they can store one char (letter). Shouldn't they be char pointers?

    Comment

    • joeschnell
      New Member
      • Apr 2007
      • 47

      #3
      Hey, I hadn't even noticed that and apparently the compiler didn't either. Your right, one is a required string that I declared wrong==I'm working on it. Been reading about structs and objects, basically they are a parent file and a child, or main and sub file creating a variable of definable attributes rather than simply a primitive variable such as int x.
      Thank you for your help, I have 10 days left to finish this code and I am more than certain I'm going to run into more problems and will be asking again for a shove in the right direction.
      Thank You
      Joe

      Comment

      • joeschnell
        New Member
        • Apr 2007
        • 47

        #4
        return 0;
        }

        do
        {
        cout << "Please enter 0 to list all movies" << endl; //makes sense to display the menu for choice
        cout << "Pleae enter 99 to end the program" << endl; //either display the menu or stop the program
        cout << "Selection: ";
        cin >> choice >> endl;
        cout << endl; << endl;
        }
        while choice !=99);

        {
        cout << setw(12) << "Oceans 13" << endl; << "Oceans 12" << endl; "Oceans 11" << endl;
        cout << "Braveheart " << endl; << "Harry Potter" << endl; << "Caligula" << endl;
        cout << setw(12) << "movie1" << "movie2" << "movie3" << "movie4" << "movie5" << "movie6" << endl;
        }

        playMovie (show movie);

        cout << "Choose a movie by entering 1 thru 6" << endl;
        cin >> choice;

        switch (movie)
        {
        case '1': movie1 = "Oceans 13 / NEW";


        OK, I think I have enough time in trying to figure out why other code I have written using a do while has worked like this, and this will not, whether I move the brace and include this in the main, or swap another module between this the compiler error keeps coming up
        "unqualifie d id before do" or expected 'or' before 'do', what are they talking about expected >or< before do? I've never heard that-
        If anyone knows where the syntax error is please feel free, it compiles through my do while now. I actually don't really see a whole lot of use for a do while other than it's a required part of the program, seems to me you can use a 'for' loop, an 'if' statement in any case avoiding these problems with this compiling. Unless I guess you for some reason had to have a post test or a pre-test loop that I can't think of. OK Here's my problem-

        Comment

        • ilikepython
          Recognized Expert Contributor
          • Feb 2007
          • 844

          #5
          Originally posted by joeschnell
          return 0;
          }

          do
          {
          cout << "Please enter 0 to list all movies" << endl; //makes sense to display the menu for choice
          cout << "Pleae enter 99 to end the program" << endl; //either display the menu or stop the program
          cout << "Selection: ";
          cin >> choice >> endl;
          cout << endl; << endl;
          }
          while choice !=99);

          {
          cout << setw(12) << "Oceans 13" << endl; << "Oceans 12" << endl; "Oceans 11" << endl;
          cout << "Braveheart " << endl; << "Harry Potter" << endl; << "Caligula" << endl;
          cout << setw(12) << "movie1" << "movie2" << "movie3" << "movie4" << "movie5" << "movie6" << endl;
          }

          playMovie (show movie);

          cout << "Choose a movie by entering 1 thru 6" << endl;
          cin >> choice;

          switch (movie)
          {
          case '1': movie1 = "Oceans 13 / NEW";


          OK, I think I have enough time in trying to figure out why other code I have written using a do while has worked like this, and this will not, whether I move the brace and include this in the main, or swap another module between this the compiler error keeps coming up
          "unqualifie d id before do" or expected 'or' before 'do', what are they talking about expected >or< before do? I've never heard that-
          If anyone knows where the syntax error is please feel free, it compiles through my do while now. I actually don't really see a whole lot of use for a do while other than it's a required part of the program, seems to me you can use a 'for' loop, an 'if' statement in any case avoiding these problems with this compiling. Unless I guess you for some reason had to have a post test or a pre-test loop that I can't think of. OK Here's my problem-
          Is your do while in a function? If it is in the middle of a source file, the compiler will generate an error. If it isn't, check your braces. If you put an extra one the compiler will think the function has ended and give an error for the do while.

          You can't include loops or ifs outside of functions. However, you can declare variables, as you probably have been doing.

          Comment

          • joeschnell
            New Member
            • Apr 2007
            • 47

            #6
            Nope, actually I don't know what I'm doing. I thought it would be easiest for me to create an IPO chart and start writing out all the modules, then edit them as I compiled down the line. I've written most of them, my array I need to figure out yet but--nothing compiles. The change I made to my struct did get it to compile down several more lines, but I don't know why so that isn't doing me much good. Why,
            void playMovie (movie) to void playMovie (movie movie_a) made the difference I don't have a clue.
            I've also been changing my struct declarations from reading other posts in here and it's simply making it more confusing. Here's the whole code so far, changed 117 times mind you, but it is just the starting modules as I said--I thought I would be able to compile through the errors one at a time but it's really getting out of hand now.


            //Assignment One CIS247 Joseph Matzke
            #include <cstdlib>
            #include <iomanip>
            #include <iostream>
            #include <string>
            using namespace std;

            struct movie
            {
            char movie; //G,PG,PG13,R17,X
            char title; //Oceans 13, Oceans 12, Oceans 11, Braveheart, Harry Potter, Caligula
            bool releaseDate; //Still in theatre-released
            char language[];//English E, Spanish S, Japanese J, Chinese C, German G, Swaheely S
            double cost;
            double tax;
            };
            void playMovie (struct movie movie_a);
            int main(void)
            {
            int choice = 0;
            //movie anyMovie; //declaration-creates object?
            movie movie1={'R', "Oceans 13", true, 'E', 19.99, .08}; //movie number 1
            movie movie2={'R', "Oceans 12", false, 'E', 9.99};
            movie movie3={'R', "Oceans 11", false, 'E', 9.99};
            movie movie4={'R', "Braveheart ", false, 'E', 9.99};
            movie movie5={'G', "Harry Potter", false, 'E', 9.99};
            movie movie6={'X', "Caligula", false, 'S', 1.99};

            system ("pause");
            return 0;
            }

            do
            {
            cout << "Please enter 0 to list all movies" << endl; //makes sense to display the menu for choice
            cout << "Pleae enter 99 to end the program" << endl; //either display the menu or stop the program
            cout << "Selection: ";
            cin >> choice >> endl;
            cout << endl; << endl;
            }
            while choice !=99);

            {
            cout << setw(12) << "Oceans 13" << endl; << "Oceans 12" << endl; "Oceans 11" << endl;
            cout << "Braveheart " << endl; << "Harry Potter" << endl; << "Caligula" << endl;
            cout << setw(12) << "movie1" << "movie2" << "movie3" << "movie4" << "movie5" << "movie6" << endl;
            }

            playMovie (show movie);

            cout << "Choose a movie by entering 1 thru 6" << endl;
            cin >> choice;

            switch (movie)
            {
            case '1': movie1 = "Oceans 13 / NEW";
            break;
            case '2': movie2 = "Oceans 12 /released";
            break;
            case '3': movie3 = "Oceans 11 /released";
            break;
            case '4': movie4 = "Braveheart /released";
            break;
            case '5': movie5 = "Harry Potter /released";
            break;
            case '6': movie6 = "Caligula /released";
            default: movie = "Invalid selection";
            }



            void playMovie (show movie)
            {
            double movie [] = {'19.99','9.99' ,'9.99','9.99', '9.99','1.99'};
            double choice [] = {0,0,0,0,0,0};

            cout << "Enter movie choice" << endl;
            cin >> choice[];
            }
            {
            if (choice == 1);
            cout << "movie[0]" << endl;
            else
            if (choice =>2 && < 6);
            cout << "movie[2]" << endl;
            else cout << "movie[5]" << endl;
            }

            movie (cost)
            {
            if (movie == 1)
            cout << "Cost is 19.99:" << endl;
            else if (movie =>1 && < 6);
            cout << "Cost is 9.99:" << endl;
            else
            cout << "Cost is 1.99:" << endl;
            }
            total (cost)
            {
            if (movie == 1)
            cost = 19.99 * .08;
            cout >> cost;
            else if (movie =>2 && < 6);
            cost = 9.99 * .08;
            cout << cost;
            else cost = 1.99 * .08;
            cout << cost;
            return cost;
            }

            cout << "You have picked movie " << movie << "your cost is " << cost << endl;




            Any suggestions, scrap this entire thing, start over using a different approach? I'm getting truly frustrated HERE!!!!!

            Comment

            • phiefer3
              New Member
              • Jun 2007
              • 67

              #7
              Originally posted by joeschnell
              Nope, actually I don't know what I'm doing. I thought it would be easiest for me to create an IPO chart and start writing out all the modules, then edit them as I compiled down the line. I've written most of them, my array I need to figure out yet but--nothing compiles. The change I made to my struct did get it to compile down several more lines, but I don't know why so that isn't doing me much good. Why,
              void playMovie (movie) to void playMovie (movie movie_a) made the difference I don't have a clue.
              I've also been changing my struct declarations from reading other posts in here and it's simply making it more confusing. Here's the whole code so far, changed 117 times mind you, but it is just the starting modules as I said--I thought I would be able to compile through the errors one at a time but it's really getting out of hand now.


              [CODE=cpp]//Assignment One CIS247 Joseph Matzke
              #include <cstdlib>
              #include <iomanip>
              #include <iostream>
              #include <string>
              using namespace std;

              struct movie
              {
              char movie; //G,PG,PG13,R17,X
              char title; //Oceans 13, Oceans 12, Oceans 11, Braveheart, Harry Potter, Caligula
              bool releaseDate; //Still in theatre-released
              char language[];//English E, Spanish S, Japanese J, Chinese C, German G, Swaheely S
              double cost;
              double tax;
              };
              void playMovie (struct movie movie_a);
              int main(void)
              {
              int choice = 0;
              //movie anyMovie; //declaration-creates object?
              movie movie1={'R', "Oceans 13", true, 'E', 19.99, .08}; //movie number 1
              movie movie2={'R', "Oceans 12", false, 'E', 9.99};
              movie movie3={'R', "Oceans 11", false, 'E', 9.99};
              movie movie4={'R', "Braveheart ", false, 'E', 9.99};
              movie movie5={'G', "Harry Potter", false, 'E', 9.99};
              movie movie6={'X', "Caligula", false, 'S', 1.99};

              system ("pause");
              return 0;
              }

              do
              {
              cout << "Please enter 0 to list all movies" << endl; //makes sense to display the menu for choice
              cout << "Pleae enter 99 to end the program" << endl; //either display the menu or stop the program
              cout << "Selection: ";
              cin >> choice >> endl;
              cout << endl; << endl;
              }
              while choice !=99);

              {
              cout << setw(12) << "Oceans 13" << endl; << "Oceans 12" << endl; "Oceans 11" << endl;
              cout << "Braveheart " << endl; << "Harry Potter" << endl; << "Caligula" << endl;
              cout << setw(12) << "movie1" << "movie2" << "movie3" << "movie4" << "movie5" << "movie6" << endl;
              }

              playMovie (show movie);

              cout << "Choose a movie by entering 1 thru 6" << endl;
              cin >> choice;

              switch (movie)
              {
              case '1': movie1 = "Oceans 13 / NEW";
              break;
              case '2': movie2 = "Oceans 12 /released";
              break;
              case '3': movie3 = "Oceans 11 /released";
              break;
              case '4': movie4 = "Braveheart /released";
              break;
              case '5': movie5 = "Harry Potter /released";
              break;
              case '6': movie6 = "Caligula /released";
              default: movie = "Invalid selection";
              }



              void playMovie (show movie)
              {
              double movie [] = {'19.99','9.99' ,'9.99','9.99', '9.99','1.99'};
              double choice [] = {0,0,0,0,0,0};

              cout << "Enter movie choice" << endl;
              cin >> choice[];
              }
              {
              if (choice == 1);
              cout << "movie[0]" << endl;
              else
              if (choice =>2 && < 6);
              cout << "movie[2]" << endl;
              else cout << "movie[5]" << endl;
              }

              movie (cost)
              {
              if (movie == 1)
              cout << "Cost is 19.99:" << endl;
              else if (movie =>1 && < 6);
              cout << "Cost is 9.99:" << endl;
              else
              cout << "Cost is 1.99:" << endl;
              }
              total (cost)
              {
              if (movie == 1)
              cost = 19.99 * .08;
              cout >> cost;
              else if (movie =>2 && < 6);
              cost = 9.99 * .08;
              cout << cost;
              else cost = 1.99 * .08;
              cout << cost;
              return cost;
              }

              cout << "You have picked movie " << movie << "your cost is " << cost << endl;[/CODE]




              Any suggestions, scrap this entire thing, start over using a different approach? I'm getting truly frustrated HERE!!!!!
              Your forgot a ( in your while statement at the end of your do loop.

              Comment

              • ilikepython
                Recognized Expert Contributor
                • Feb 2007
                • 844

                #8
                Originally posted by joeschnell
                Nope, actually I don't know what I'm doing. I thought it would be easiest for me to create an IPO chart and start writing out all the modules, then edit them as I compiled down the line. I've written most of them, my array I need to figure out yet but--nothing compiles. The change I made to my struct did get it to compile down several more lines, but I don't know why so that isn't doing me much good. Why,
                void playMovie (movie) to void playMovie (movie movie_a) made the difference I don't have a clue.
                I've also been changing my struct declarations from reading other posts in here and it's simply making it more confusing. Here's the whole code so far, changed 117 times mind you, but it is just the starting modules as I said--I thought I would be able to compile through the errors one at a time but it's really getting out of hand now.


                //Assignment One CIS247 Joseph Matzke
                #include <cstdlib>
                #include <iomanip>
                #include <iostream>
                #include <string>
                using namespace std;

                struct movie
                {
                char movie; //G,PG,PG13,R17,X
                char title; //Oceans 13, Oceans 12, Oceans 11, Braveheart, Harry Potter, Caligula
                bool releaseDate; //Still in theatre-released
                char language[];//English E, Spanish S, Japanese J, Chinese C, German G, Swaheely S
                double cost;
                double tax;
                };
                void playMovie (struct movie movie_a);
                int main(void)
                {
                int choice = 0;
                //movie anyMovie; //declaration-creates object?
                movie movie1={'R', "Oceans 13", true, 'E', 19.99, .08}; //movie number 1
                movie movie2={'R', "Oceans 12", false, 'E', 9.99};
                movie movie3={'R', "Oceans 11", false, 'E', 9.99};
                movie movie4={'R', "Braveheart ", false, 'E', 9.99};
                movie movie5={'G', "Harry Potter", false, 'E', 9.99};
                movie movie6={'X', "Caligula", false, 'S', 1.99};

                system ("pause");
                return 0;
                }

                do
                {
                cout << "Please enter 0 to list all movies" << endl; //makes sense to display the menu for choice
                cout << "Pleae enter 99 to end the program" << endl; //either display the menu or stop the program
                cout << "Selection: ";
                cin >> choice >> endl;
                cout << endl; << endl;
                }
                while choice !=99);

                {
                cout << setw(12) << "Oceans 13" << endl; << "Oceans 12" << endl; "Oceans 11" << endl;
                cout << "Braveheart " << endl; << "Harry Potter" << endl; << "Caligula" << endl;
                cout << setw(12) << "movie1" << "movie2" << "movie3" << "movie4" << "movie5" << "movie6" << endl;
                }

                playMovie (show movie);

                cout << "Choose a movie by entering 1 thru 6" << endl;
                cin >> choice;

                switch (movie)
                {
                case '1': movie1 = "Oceans 13 / NEW";
                break;
                case '2': movie2 = "Oceans 12 /released";
                break;
                case '3': movie3 = "Oceans 11 /released";
                break;
                case '4': movie4 = "Braveheart /released";
                break;
                case '5': movie5 = "Harry Potter /released";
                break;
                case '6': movie6 = "Caligula /released";
                default: movie = "Invalid selection";
                }



                void playMovie (show movie)
                {
                double movie [] = {'19.99','9.99' ,'9.99','9.99', '9.99','1.99'};
                double choice [] = {0,0,0,0,0,0};

                cout << "Enter movie choice" << endl;
                cin >> choice[];
                }
                {
                if (choice == 1);
                cout << "movie[0]" << endl;
                else
                if (choice =>2 && < 6);
                cout << "movie[2]" << endl;
                else cout << "movie[5]" << endl;
                }

                movie (cost)
                {
                if (movie == 1)
                cout << "Cost is 19.99:" << endl;
                else if (movie =>1 && < 6);
                cout << "Cost is 9.99:" << endl;
                else
                cout << "Cost is 1.99:" << endl;
                }
                total (cost)
                {
                if (movie == 1)
                cost = 19.99 * .08;
                cout >> cost;
                else if (movie =>2 && < 6);
                cost = 9.99 * .08;
                cout << cost;
                else cost = 1.99 * .08;
                cout << cost;
                return cost;
                }

                cout << "You have picked movie " << movie << "your cost is " << cost << endl;




                Any suggestions, scrap this entire thing, start over using a different approach? I'm getting truly frustrated HERE!!!!!
                Ok, first of all you need to relax, don't get so frustrated.

                First of all, you don't need to write struct in front of the struct name in the prototype:
                [code=cpp]
                void playMovie(movie );
                [/code]
                should work.
                [code=cpp]
                int main(void)
                {
                int choice = 0;
                //movie anyMovie; //declaration-creates object?
                movie movie1={'R', "Oceans 13", true, 'E', 19.99, .08}; //movie number 1
                movie movie2={'R', "Oceans 12", false, 'E', 9.99};
                movie movie3={'R', "Oceans 11", false, 'E', 9.99};
                movie movie4={'R', "Braveheart ", false, 'E', 9.99};
                movie movie5={'G', "Harry Potter", false, 'E', 9.99};
                movie movie6={'X', "Caligula", false, 'S', 1.99};

                system ("pause");
                return 0;
                }
                [/code]
                Ok, so you declared your movies, but you ended main and continued writing the program outside a function! That's probably the cause of most of your errors.

                continuing main...
                [code=cpp]
                do
                {
                cout << "Please enter 0 to list all movies" << endl; //makes sense to display the menu for choice
                cout << "Pleae enter 99 to end the program" << endl; //either display the menu or stop the program
                cout << "Selection: ";
                cin >> choice >> endl;
                cout << endl; << endl;
                }
                while choice !=99);

                {
                cout << setw(12) << "Oceans 13" << endl; << "Oceans 12" << endl; "Oceans 11" << endl;
                cout << "Braveheart " << endl; << "Harry Potter" << endl; << "Caligula" << endl;
                cout << setw(12) << "movie1" << "movie2" << "movie3" << "movie4" << "movie5" << "movie6" << endl;
                }
                [/code]
                Your do while loop is a bit confusing. Is this what you were looking for:
                [code=cpp]
                do
                {
                cout << "Please enter 0 to list all movies" << endl;
                cout << "Please enter 99 to exit program" << endl;
                cout << "Selection: ";
                cin >> choice;
                }
                while( choice != 0 && choice != 99); // go back if choice not 0 or 99

                if (choice == 99)
                {
                return 0; // exit prgoram
                }

                if (choice == 0)
                {
                cout << setw(12) << "Oceans 13" << endl; << "Oceans 12" << endl; "Oceans 11" << endl;
                cout << "Braveheart " << endl; << "Harry Potter" << endl; << "Caligula" << endl;
                cout << setw(12) << "movie1" << "movie2" << "movie3" << "movie4" << "movie5" << "movie6" << endl;
                }
                [/code]
                So far so good.
                [code=cpp]
                playMovie (show movie); // invalid syntax

                cout << "Choose a movie by entering 1 thru 6" << endl;
                cin >> choice;

                switch (movie)
                {
                case '1': movie1 = "Oceans 13 / NEW";
                break;
                case '2': movie2 = "Oceans 12 /released";
                break;
                case '3': movie3 = "Oceans 11 /released";
                break;
                case '4': movie4 = "Braveheart /released";
                break;
                case '5': movie5 = "Harry Potter /released";
                break;
                case '6': movie6 = "Caligula /released";
                default: movie = "Invalid selection";
                }
                [/code]
                You never declared movie. Did you mean to put choice in the switch? Is play movie supposed to display everything about the movie (all the variables in the struct)? Try something like this:
                [code=cpp]
                cout << "Choose a movie be entering 1 - 6" << endl;
                cout << "Selection: ";
                cin >> choice;

                movie *pmovie; = NULL; // pointer to movie that user chooses

                switch (choice)
                {
                case 1:
                pmovie = &movie1;
                break;
                case 2:
                pmovie = &movie2;
                break;
                case 3:
                pmovie = &movie3;
                break;
                case 4:
                pmovie = &movie4;
                break;
                case 5:
                pmovie = &movie5;
                break;
                case 6:
                pmovie = &movie6;
                break;
                }

                if (pmovie != NULL)
                {
                playMovie(*pmov ie);
                }
                [/code]
                Try to correct playMovie yourself and come here if you have any questions. Also, if you don't understand anything just ask.

                PS. Please use code tags, it makes your code easier to read and understand.

                Comment

                • joeschnell
                  New Member
                  • Apr 2007
                  • 47

                  #9
                  OK, thank you for taking the time to explain that all to me!! It is making sense now and is a bit embarrassing some of the glaring errors such as writing outside of the function....... ....I know that much at least. I am reading all I can on pointers, in here and my text book and it's fairly deep and a bit hard to wrap your head around, but-I am determined to get this thing nailed down and understood.
                  I was wondering why he was giving us two weeks instead of last terms usual two hours, or two days, and I now know why it is taking me that long!
                  Thanks again python, that was very cool of you to take the time to explain for what I am sure are obvious C++ for DUMMIES mistakes to you.
                  Joe

                  Comment

                  • joeschnell
                    New Member
                    • Apr 2007
                    • 47

                    #10
                    Well just to get some things settled I thought I would give it a go to compile and get through just main once to get that great feeling of accomplishment, yet to the detriment of my pc and a bit of abuse to the defenseless mouse I see that very familiar "EXCESS ELEMENTS IN AGGREGATE INITIALIZER"...
                    I have the same amount of elements in my struct initialized as I have declared which puzzles me, even makes me think it may be my using Dev, rather than that wonderfully helpful VS edition I've installed that came with our software bundle. However nobody uses it, because it is such a crappy environment with incomprehensibl e error messages in keeping with that great Microsoft tradition of over complication. Simplification is the ultimate sophistication should be their corporate mission statement but it's not. Does anyone believe some of my problems would go away if I were to use Visual Studio? Why would it be that an equally amount of declared sub sets in a struct, which is 6, along with the initialized six produces the error message above in upper case?? There is obviously some logic I am not aware of when attempting to create an OOP. I didn't have quite this much trouble with first attempts at any other type of brand new introductions I was given, anyone have some compiler knowledge that can interpret this message for me it would be greatly appreciated.
                    Joe

                    Code:
                     //Assignment One CIS247 Joseph Matzke
                    #include <cstdlib>
                    #include <iomanip>
                    #include <iostream>
                    #include <string>
                    using namespace std;
                    
                    struct movie
                    {
                           char rating; //G,PG,PG13,R17,X
                           string movie; //Oceans 13, Oceans 12, Oceans 11, Braveheart, Harry Potter, Caligula
                           bool releaseDate[]; //Still in theatre-released
                           char language;//English E, Spanish S, Japanese J, Chinese C, German G, Swaheely S
                           double cost; 
                           double tax;
                    };
                    void playMovie (movie);
                    int main(void)
                    {
                        int choice = 0;
                        //movie anyMovie;  //declaration-creates object?
                        movie movie1={'R', "Oceans 13", true, 'E', 19.99, .08}; //movie number 1
                        movie movie2={'R', "Oceans 12", false, 'E', 9.99};
                        movie movie3={'R', "Oceans 11", false, 'E', 9.99};
                        movie movie4={'R', "Braveheart", false, 'E', 9.99};
                        movie movie5={'G', "Harry Potter", false, 'E', 9.99};
                        movie movie6={'X', "Caligula", false, 'S', 1.99}; 
                        
                        //system ("pause");
                        //return 0;
                    //}
                           
                       do  
                       {
                           cout << "Please enter 0 to list all movies" << endl; //makes sense to display the menu for choice
                           cout << "Pleae enter 99 to end the program" << endl; //either display the menu or stop the program
                           cout << "Selection:  ";
                           cin >> choice >> endl;
                           cout << endl; << endl;
                       }
                           while (choice != 0 && choice !=99);//repeat if choice not 0 or 99
                           
                           if (choice == 99)
                           {
                                      system ("pause");
                                      return 0;
                           }
                           if (choice == 0)
                           
                      {     
                           cout << setw(12) << "Oceans 13" << endl; << "Oceans 12" << endl; "Oceans 11" << endl;
                           cout << "Braveheart" << endl; << "Harry Potter" << endl; << "Caligula" << endl;
                           cout << setw(12) << "movie1" << "movie2" << "movie3" << "movie4" << "movie5" << "movie6" << endl;
                      }         
                               
                    playMovie (movie);
                    
                    cout << "Choose a movie by entering 1 thru 6" << endl;
                    cout << "Selection :";
                    cin >> choice;
                    
                    movie *pmovie; = NULL;  //pointer to movie that user chooses
                    
                    switch (choice)
                    {
                        case 1:
                             pmovie = &movie1;
                             break;
                        case 2:
                             pmovie = &movie2;
                             break;
                        case 3:
                             pmovie = &movie3;
                             break;
                        case 4:
                             pmovie = &movie4;
                             break;
                        case 5:
                             pmovie = &movie5;
                             break;
                        case 6:
                             pmovie = &movie6;
                             break;
                    }
                        if (pmovie != NULL)
                    {
                                   playMovie (*pmovie);
                    }
                    
                      
                      void playMovie (releaseDate[])
                      {
                           double movie [] = {'19.99','9.99','9.99','9.99','9.99','1.99'};
                           double choice [] = {0,0,0,0,0,0};
                           
                           cout << "Enter movie choice" << endl;
                           cin >> choice[];
                      //}
                      //{
                           if (choice == 1);
                           cout << "movie[0]" << endl;
                             else 
                               if (choice =>2 && < 6);
                               cout << "movie[2]" << endl;
                                 else cout << "movie[5]" << endl;
                      }
                           
                           void playMovie (cost)
                           {
                                 if (movie == 1)
                                 cout << "Cost is 19.99:" << endl;
                                 else if (movie =>1 && < 6);
                                 cout << "Cost is 9.99:" << endl;
                                 else 
                                 cout << "Cost is 1.99:" << endl;
                           }
                           total (cost)
                           {
                           if (movie == 1)
                           cost = 19.99 * .08;
                           cout >> cost;
                           else if (movie =>2 && < 6);
                           cost = 9.99 * .08;
                           cout << cost;
                           else cost = 1.99 * .08;
                           cout << cost;
                           return cost;
                           }
                           
                           cout << "You have chosen movie " << *pmovie << "your cost is " << cost << endl;

                    Comment

                    • joeschnell
                      New Member
                      • Apr 2007
                      • 47

                      #11
                      Oh, now that I'm catching on to how to post correctly here for ease of discussion it is line 22 that the compiler is spitting out that message to me on.
                      Who wrote this shell? Very cool-

                      Comment

                      • ilikepython
                        Recognized Expert Contributor
                        • Feb 2007
                        • 844

                        #12
                        Originally posted by joeschnell
                        Well just to get some things settled I thought I would give it a go to compile and get through just main once to get that great feeling of accomplishment, yet to the detriment of my pc and a bit of abuse to the defenseless mouse I see that very familiar "EXCESS ELEMENTS IN AGGREGATE INITIALIZER"...
                        I have the same amount of elements in my struct initialized as I have declared which puzzles me, even makes me think it may be my using Dev, rather than that wonderfully helpful VS edition I've installed that came with our software bundle. However nobody uses it, because it is such a crappy environment with incomprehensibl e error messages in keeping with that great Microsoft tradition of over complication. Simplification is the ultimate sophistication should be their corporate mission statement but it's not. Does anyone believe some of my problems would go away if I were to use Visual Studio? Why would it be that an equally amount of declared sub sets in a struct, which is 6, along with the initialized six produces the error message above in upper case?? There is obviously some logic I am not aware of when attempting to create an OOP. I didn't have quite this much trouble with first attempts at any other type of brand new introductions I was given, anyone have some compiler knowledge that can interpret this message for me it would be greatly appreciated.
                        Joe

                        Code:
                         //Assignment One CIS247 Joseph Matzke
                        #include <cstdlib>
                        #include <iomanip>
                        #include <iostream>
                        #include <string>
                        using namespace std;
                        
                        struct movie
                        {
                               char rating; //G,PG,PG13,R17,X
                               string movie; //Oceans 13, Oceans 12, Oceans 11, Braveheart, Harry Potter, Caligula
                               bool releaseDate[]; //Still in theatre-released
                               char language;//English E, Spanish S, Japanese J, Chinese C, German G, Swaheely S
                               double cost; 
                               double tax;
                        };
                        void playMovie (movie);
                        int main(void)
                        {
                            int choice = 0;
                            //movie anyMovie;  //declaration-creates object?
                            movie movie1={'R', "Oceans 13", true, 'E', 19.99, .08}; //movie number 1
                            movie movie2={'R', "Oceans 12", false, 'E', 9.99};
                            movie movie3={'R', "Oceans 11", false, 'E', 9.99};
                            movie movie4={'R', "Braveheart", false, 'E', 9.99};
                            movie movie5={'G', "Harry Potter", false, 'E', 9.99};
                            movie movie6={'X', "Caligula", false, 'S', 1.99}; 
                            
                            //system ("pause");
                            //return 0;
                        //}
                               
                           do  
                           {
                               cout << "Please enter 0 to list all movies" << endl; //makes sense to display the menu for choice
                               cout << "Pleae enter 99 to end the program" << endl; //either display the menu or stop the program
                               cout << "Selection:  ";
                               cin >> choice >> endl;
                               cout << endl; << endl;
                           }
                               while (choice != 0 && choice !=99);//repeat if choice not 0 or 99
                               
                               if (choice == 99)
                               {
                                          system ("pause");
                                          return 0;
                               }
                               if (choice == 0)
                               
                          {     
                               cout << setw(12) << "Oceans 13" << endl; << "Oceans 12" << endl; "Oceans 11" << endl;
                               cout << "Braveheart" << endl; << "Harry Potter" << endl; << "Caligula" << endl;
                               cout << setw(12) << "movie1" << "movie2" << "movie3" << "movie4" << "movie5" << "movie6" << endl;
                          }         
                                   
                        playMovie (movie);
                        
                        cout << "Choose a movie by entering 1 thru 6" << endl;
                        cout << "Selection :";
                        cin >> choice;
                        
                        movie *pmovie; = NULL;  //pointer to movie that user chooses
                        
                        switch (choice)
                        {
                            case 1:
                                 pmovie = &movie1;
                                 break;
                            case 2:
                                 pmovie = &movie2;
                                 break;
                            case 3:
                                 pmovie = &movie3;
                                 break;
                            case 4:
                                 pmovie = &movie4;
                                 break;
                            case 5:
                                 pmovie = &movie5;
                                 break;
                            case 6:
                                 pmovie = &movie6;
                                 break;
                        }
                            if (pmovie != NULL)
                        {
                                       playMovie (*pmovie);
                        }
                        
                          
                          void playMovie (releaseDate[])
                          {
                               double movie [] = {'19.99','9.99','9.99','9.99','9.99','1.99'};
                               double choice [] = {0,0,0,0,0,0};
                               
                               cout << "Enter movie choice" << endl;
                               cin >> choice[];
                          //}
                          //{
                               if (choice == 1);
                               cout << "movie[0]" << endl;
                                 else 
                                   if (choice =>2 && < 6);
                                   cout << "movie[2]" << endl;
                                     else cout << "movie[5]" << endl;
                          }
                               
                               void playMovie (cost)
                               {
                                     if (movie == 1)
                                     cout << "Cost is 19.99:" << endl;
                                     else if (movie =>1 && < 6);
                                     cout << "Cost is 9.99:" << endl;
                                     else 
                                     cout << "Cost is 1.99:" << endl;
                               }
                               total (cost)
                               {
                               if (movie == 1)
                               cost = 19.99 * .08;
                               cout >> cost;
                               else if (movie =>2 && < 6);
                               cost = 9.99 * .08;
                               cout << cost;
                               else cost = 1.99 * .08;
                               cout << cost;
                               return cost;
                               }
                               
                               cout << "You have chosen movie " << *pmovie << "your cost is " << cost << endl;
                        Let's sse your struct:
                        [code=cpp]
                        struct movie
                        {
                        char rating; //G,PG,PG13,R17,X
                        string movie; //Oceans 13, Oceans 12, Oceans 11, Braveheart, Harry Potter, Caligula
                        bool releaseDate[]; //Still in theatre-released
                        char language;//English E, Spanish S, Japanese J, Chinese C, German G, Swaheely S
                        double cost;
                        double tax;
                        };
                        [/code]
                        releaseDate is an array of bools, you are giving it a bool when declaring your movies. I assume you only need 1 bool, so take off the square brackets, and those errors will dissapear (I tried it).
                        If you want an array you have to put a number in the brackets.

                        Comment

                        • ilikepython
                          Recognized Expert Contributor
                          • Feb 2007
                          • 844

                          #13
                          Originally posted by ilikepython
                          Let's sse your struct:
                          [code=cpp]
                          struct movie
                          {
                          char rating; //G,PG,PG13,R17,X
                          string movie; //Oceans 13, Oceans 12, Oceans 11, Braveheart, Harry Potter, Caligula
                          bool releaseDate[]; //Still in theatre-released
                          char language;//English E, Spanish S, Japanese J, Chinese C, German G, Swaheely S
                          double cost;
                          double tax;
                          };
                          [/code]
                          releaseDate is an array of bools, you are giving it a bool when declaring your movies. I assume you only need 1 bool, so take off the square brackets, and those errors will dissapear (I tried it).
                          If you want an array you have to put a number in the brackets.
                          Well, apperantly my post didn't show up but if you click reply you can see what I wrote.

                          Edit: Well, it shows up in the quotes so that's kind of wierd. I've seen it happen to other people too.

                          Comment

                          • joeschnell
                            New Member
                            • Apr 2007
                            • 47

                            #14
                            Got it, I'm down to line beyond main now and it's exciting. I found some pages where you can get some explanation of compiler error messages at

                            http://www.csee.umbc.e du/courses/undergraduate/341/misc/CommonErrors.sh tml

                            but it doesn't contain what I am looking for. In particular I am looking for "expected primary-expression before '<<' token", and am going to keep on looking!

                            The pointers I have some questions on but from what I've read, and what is contained in the program once the syntax errors are gone and I can see the output I'm sure I'll be able to play with it and get a much better feel for what I do understand and what I don't understand--so for now I'll not ask redundant questions that may or may not be answered once I get this thing to compile.
                            Using an array for a bool is, pretty dumb now that I'm looking at it. It was really a short cut to get my required array in the program, but if I'm going to use an array I might as well use it for what it's intended for as in my movie titles or some other menu type deal, that way I think I could use a char memory allocation for my string titles and cut down on memory use. I'm actually going to change a bunch of things if I could get some output to dislike.
                            Thank you for your help, when I get truly stuck again I'll be back, which means to say probably in a few hours-).
                            Thanks Python

                            Comment

                            • joeschnell
                              New Member
                              • Apr 2007
                              • 47

                              #15
                              Ahh, I am soo used to the error being on the line prior this is truly embarrassing. After changing every ; << and { in the first 50 lines I realized the line itself contained the error.
                              This will cause an error: cout << setw(12) << "Money" << endl; << "Braveheart " << endl; cout << "..." << endl;

                              I can see that running your code in one big long line is very dangerous for the chance of having errors that are not very obvious, such as missing a cout.

                              Unbelievable. OK, I'm getting there.

                              Comment

                              Working...