473,671 Members | 2,250 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Structs in C++ using prototypes from the beginning

47 New Member
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
Jul 21 '07 #1
38 3027
ilikepython
844 Recognized Expert Contributor
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:
Expand|Select|Wrap|Line Numbers
  1. void playMovie(movie movie_a);
  2.  
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?
Jul 21 '07 #2
joeschnell
47 New Member
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
Jul 22 '07 #3
joeschnell
47 New Member
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-
Jul 22 '07 #4
ilikepython
844 Recognized Expert Contributor
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.
Jul 22 '07 #5
joeschnell
47 New Member
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!!!!!
Jul 22 '07 #6
phiefer3
67 New Member
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.


Expand|Select|Wrap|Line Numbers
  1. //Assignment One CIS247 Joseph Matzke
  2. #include <cstdlib>
  3. #include <iomanip>
  4. #include <iostream>
  5. #include <string>
  6. using namespace std;
  7.  
  8. struct movie
  9. {
  10.        char movie; //G,PG,PG13,R17,X
  11.        char title; //Oceans 13, Oceans 12, Oceans 11, Braveheart, Harry Potter, Caligula
  12.        bool releaseDate; //Still in theatre-released
  13.        char language[];//English E, Spanish S, Japanese J, Chinese C, German G, Swaheely S
  14.        double cost; 
  15.        double tax;
  16. };
  17. void playMovie (struct movie movie_a);
  18. int main(void)
  19. {
  20.     int choice = 0;
  21.     //movie anyMovie;  //declaration-creates object?
  22.     movie movie1={'R', "Oceans 13", true, 'E', 19.99, .08}; //movie number 1
  23.     movie movie2={'R', "Oceans 12", false, 'E', 9.99};
  24.     movie movie3={'R', "Oceans 11", false, 'E', 9.99};
  25.     movie movie4={'R', "Braveheart", false, 'E', 9.99};
  26.     movie movie5={'G', "Harry Potter", false, 'E', 9.99};
  27.     movie movie6={'X', "Caligula", false, 'S', 1.99}; 
  28.  
  29.     system ("pause");
  30.     return 0;
  31. }
  32.  
  33.    do  
  34.    {
  35.        cout << "Please enter 0 to list all movies" << endl; //makes sense to display the menu for choice
  36.        cout << "Pleae enter 99 to end the program" << endl; //either display the menu or stop the program
  37.        cout << "Selection:  ";
  38.        cin >> choice >> endl;
  39.        cout << endl; << endl;
  40.    }
  41.        while choice !=99);
  42.  
  43.   {     
  44.        cout << setw(12) << "Oceans 13" << endl; << "Oceans 12" << endl; "Oceans 11" << endl;
  45.        cout << "Braveheart" << endl; << "Harry Potter" << endl; << "Caligula" << endl;
  46.        cout << setw(12) << "movie1" << "movie2" << "movie3" << "movie4" << "movie5" << "movie6" << endl;
  47.   }         
  48.  
  49. playMovie (show movie);
  50.  
  51. cout << "Choose a movie by entering 1 thru 6" << endl;
  52. cin >> choice;
  53.  
  54. switch (movie)
  55. {
  56.     case '1': movie1 = "Oceans 13 / NEW";
  57.     break;
  58.     case '2': movie2 = "Oceans 12 /released"; 
  59.     break;
  60.     case '3': movie3 = "Oceans 11 /released";
  61.     break;
  62.     case '4': movie4 = "Braveheart /released";
  63.     break;
  64.     case '5': movie5 = "Harry Potter /released";
  65.     break;
  66.     case '6': movie6 = "Caligula /released";
  67.     default: movie = "Invalid selection";
  68. }
  69.  
  70.  
  71.  
  72.   void playMovie (show movie)
  73.   {
  74.        double movie [] = {'19.99','9.99','9.99','9.99','9.99','1.99'};
  75.        double choice [] = {0,0,0,0,0,0};
  76.  
  77.        cout << "Enter movie choice" << endl;
  78.        cin >> choice[];
  79.   }
  80.   {
  81.        if (choice == 1);
  82.        cout << "movie[0]" << endl;
  83.          else 
  84.            if (choice =>2 && < 6);
  85.            cout << "movie[2]" << endl;
  86.              else cout << "movie[5]" << endl;
  87.   }
  88.  
  89.        movie (cost)
  90.        {
  91.              if (movie == 1)
  92.              cout << "Cost is 19.99:" << endl;
  93.              else if (movie =>1 && < 6);
  94.              cout << "Cost is 9.99:" << endl;
  95.              else 
  96.              cout << "Cost is 1.99:" << endl;
  97.        }
  98.        total (cost)
  99.        {
  100.        if (movie == 1)
  101.        cost = 19.99 * .08;
  102.        cout >> cost;
  103.        else if (movie =>2 && < 6);
  104.        cost = 9.99 * .08;
  105.        cout << cost;
  106.        else cost = 1.99 * .08;
  107.        cout << cost;
  108.        return cost;
  109.        }
  110.  
  111.        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!!!!!
Your forgot a ( in your while statement at the end of your do loop.
Jul 22 '07 #7
ilikepython
844 Recognized Expert Contributor
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:
Expand|Select|Wrap|Line Numbers
  1. void playMovie(movie);
  2.  
should work.
Expand|Select|Wrap|Line Numbers
  1. int main(void)
  2. {
  3.     int choice = 0;
  4.     //movie anyMovie;  //declaration-creates object?
  5.     movie movie1={'R', "Oceans 13", true, 'E', 19.99, .08}; //movie number 1
  6.     movie movie2={'R', "Oceans 12", false, 'E', 9.99};
  7.     movie movie3={'R', "Oceans 11", false, 'E', 9.99};
  8.     movie movie4={'R', "Braveheart", false, 'E', 9.99};
  9.     movie movie5={'G', "Harry Potter", false, 'E', 9.99};
  10.     movie movie6={'X', "Caligula", false, 'S', 1.99}; 
  11.  
  12.     system ("pause");
  13.     return 0;
  14. }
  15.  
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...
Expand|Select|Wrap|Line Numbers
  1.  do  
  2.    {
  3.        cout << "Please enter 0 to list all movies" << endl; //makes sense to display the menu for choice
  4.        cout << "Pleae enter 99 to end the program" << endl; //either display the menu or stop the program
  5.        cout << "Selection:  ";
  6.        cin >> choice >> endl;
  7.        cout << endl; << endl;
  8.    }
  9.        while choice !=99);
  10.  
  11.   {     
  12.        cout << setw(12) << "Oceans 13" << endl; << "Oceans 12" << endl; "Oceans 11" << endl;
  13.        cout << "Braveheart" << endl; << "Harry Potter" << endl; << "Caligula" << endl;
  14.        cout << setw(12) << "movie1" << "movie2" << "movie3" << "movie4" << "movie5" << "movie6" << endl;
  15.   }         
  16.  
Your do while loop is a bit confusing. Is this what you were looking for:
Expand|Select|Wrap|Line Numbers
  1. do
  2. {
  3.     cout << "Please enter 0 to list all movies" << endl;
  4.     cout << "Please enter 99 to exit program" << endl;   
  5.     cout << "Selection: ";
  6.     cin >> choice;
  7. }
  8. while( choice != 0 && choice != 99);   // go back if choice not 0 or 99
  9.  
  10. if (choice == 99)
  11. {
  12.     return 0;        // exit prgoram
  13. }
  14.  
  15. if (choice == 0)
  16. {
  17.     cout << setw(12) << "Oceans 13" << endl; << "Oceans 12" << endl; "Oceans 11" << endl;
  18.        cout << "Braveheart" << endl; << "Harry Potter" << endl; << "Caligula" << endl;
  19.        cout << setw(12) << "movie1" << "movie2" << "movie3" << "movie4" << "movie5" << "movie6" << endl;
  20. }
  21.  
So far so good.
Expand|Select|Wrap|Line Numbers
  1. playMovie (show movie);     // invalid syntax
  2.  
  3. cout << "Choose a movie by entering 1 thru 6" << endl;
  4. cin >> choice;
  5.  
  6. switch (movie)
  7. {
  8.     case '1': movie1 = "Oceans 13 / NEW";
  9.     break;
  10.     case '2': movie2 = "Oceans 12 /released"; 
  11.     break;
  12.     case '3': movie3 = "Oceans 11 /released";
  13.     break;
  14.     case '4': movie4 = "Braveheart /released";
  15.     break;
  16.     case '5': movie5 = "Harry Potter /released";
  17.     break;
  18.     case '6': movie6 = "Caligula /released";
  19.     default: movie = "Invalid selection";
  20. }
  21.  
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:
Expand|Select|Wrap|Line Numbers
  1. cout << "Choose a movie be entering 1 - 6" << endl;
  2. cout << "Selection: ";
  3. cin >> choice;
  4.  
  5. movie *pmovie; = NULL;   // pointer to movie that user chooses
  6.  
  7. switch (choice)
  8. {
  9.     case 1:
  10.         pmovie = &movie1;
  11.         break;
  12.     case 2:
  13.         pmovie = &movie2;
  14.         break;
  15.     case 3:
  16.         pmovie = &movie3;
  17.         break;
  18.     case 4:
  19.         pmovie = &movie4;
  20.         break;
  21.     case 5:
  22.         pmovie = &movie5;
  23.         break;
  24.     case 6:
  25.         pmovie = &movie6;
  26.         break;
  27. }
  28.  
  29. if (pmovie != NULL)
  30. {
  31.     playMovie(*pmovie);
  32. }
  33.  
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.
Jul 22 '07 #8
joeschnell
47 New Member
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
Jul 23 '07 #9
joeschnell
47 New Member
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

Expand|Select|Wrap|Line Numbers
  1.  //Assignment One CIS247 Joseph Matzke
  2. #include <cstdlib>
  3. #include <iomanip>
  4. #include <iostream>
  5. #include <string>
  6. using namespace std;
  7.  
  8. struct movie
  9. {
  10.        char rating; //G,PG,PG13,R17,X
  11.        string movie; //Oceans 13, Oceans 12, Oceans 11, Braveheart, Harry Potter, Caligula
  12.        bool releaseDate[]; //Still in theatre-released
  13.        char language;//English E, Spanish S, Japanese J, Chinese C, German G, Swaheely S
  14.        double cost; 
  15.        double tax;
  16. };
  17. void playMovie (movie);
  18. int main(void)
  19. {
  20.     int choice = 0;
  21.     //movie anyMovie;  //declaration-creates object?
  22.     movie movie1={'R', "Oceans 13", true, 'E', 19.99, .08}; //movie number 1
  23.     movie movie2={'R', "Oceans 12", false, 'E', 9.99};
  24.     movie movie3={'R', "Oceans 11", false, 'E', 9.99};
  25.     movie movie4={'R', "Braveheart", false, 'E', 9.99};
  26.     movie movie5={'G', "Harry Potter", false, 'E', 9.99};
  27.     movie movie6={'X', "Caligula", false, 'S', 1.99}; 
  28.  
  29.     //system ("pause");
  30.     //return 0;
  31. //}
  32.  
  33.    do  
  34.    {
  35.        cout << "Please enter 0 to list all movies" << endl; //makes sense to display the menu for choice
  36.        cout << "Pleae enter 99 to end the program" << endl; //either display the menu or stop the program
  37.        cout << "Selection:  ";
  38.        cin >> choice >> endl;
  39.        cout << endl; << endl;
  40.    }
  41.        while (choice != 0 && choice !=99);//repeat if choice not 0 or 99
  42.  
  43.        if (choice == 99)
  44.        {
  45.                   system ("pause");
  46.                   return 0;
  47.        }
  48.        if (choice == 0)
  49.  
  50.   {     
  51.        cout << setw(12) << "Oceans 13" << endl; << "Oceans 12" << endl; "Oceans 11" << endl;
  52.        cout << "Braveheart" << endl; << "Harry Potter" << endl; << "Caligula" << endl;
  53.        cout << setw(12) << "movie1" << "movie2" << "movie3" << "movie4" << "movie5" << "movie6" << endl;
  54.   }         
  55.  
  56. playMovie (movie);
  57.  
  58. cout << "Choose a movie by entering 1 thru 6" << endl;
  59. cout << "Selection :";
  60. cin >> choice;
  61.  
  62. movie *pmovie; = NULL;  //pointer to movie that user chooses
  63.  
  64. switch (choice)
  65. {
  66.     case 1:
  67.          pmovie = &movie1;
  68.          break;
  69.     case 2:
  70.          pmovie = &movie2;
  71.          break;
  72.     case 3:
  73.          pmovie = &movie3;
  74.          break;
  75.     case 4:
  76.          pmovie = &movie4;
  77.          break;
  78.     case 5:
  79.          pmovie = &movie5;
  80.          break;
  81.     case 6:
  82.          pmovie = &movie6;
  83.          break;
  84. }
  85.     if (pmovie != NULL)
  86. {
  87.                playMovie (*pmovie);
  88. }
  89.  
  90.  
  91.   void playMovie (releaseDate[])
  92.   {
  93.        double movie [] = {'19.99','9.99','9.99','9.99','9.99','1.99'};
  94.        double choice [] = {0,0,0,0,0,0};
  95.  
  96.        cout << "Enter movie choice" << endl;
  97.        cin >> choice[];
  98.   //}
  99.   //{
  100.        if (choice == 1);
  101.        cout << "movie[0]" << endl;
  102.          else 
  103.            if (choice =>2 && < 6);
  104.            cout << "movie[2]" << endl;
  105.              else cout << "movie[5]" << endl;
  106.   }
  107.  
  108.        void playMovie (cost)
  109.        {
  110.              if (movie == 1)
  111.              cout << "Cost is 19.99:" << endl;
  112.              else if (movie =>1 && < 6);
  113.              cout << "Cost is 9.99:" << endl;
  114.              else 
  115.              cout << "Cost is 1.99:" << endl;
  116.        }
  117.        total (cost)
  118.        {
  119.        if (movie == 1)
  120.        cost = 19.99 * .08;
  121.        cout >> cost;
  122.        else if (movie =>2 && < 6);
  123.        cost = 9.99 * .08;
  124.        cout << cost;
  125.        else cost = 1.99 * .08;
  126.        cout << cost;
  127.        return cost;
  128.        }
  129.  
  130.        cout << "You have chosen movie " << *pmovie << "your cost is " << cost << endl; 
Jul 23 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

30
4243
by: stephen henry | last post by:
Hi all, I have a question that I'm having difficulty answering. If I have a struct: typedef struct my_struct_tag{ struct my_other_struct *other; } my_struct_tag
5
2910
by: Bilgehan.Balban | last post by:
Hi, I am currently brushing up my c++ knowledge and I would like to ask you about the differences between classes and C structs, in the function/method perspective. 1) Is it correct to say that, a structure definition that includes function pointers only defines the function prototypes to be used with them, but not the actual implementations, whereas in C++, member functions cannot be changed *unless* virtual functions are used, or the
20
2626
by: pinkfloydhomer | last post by:
Is it well-defined and portable to do something like: typedef struct { int type; char c; } S1; typedef struct {
61
3741
by: Marty | last post by:
I am new to C# and to structs so this could be easy or just not possible. I have a struct defined called Branch If I use Branch myBranch = new Branch(i); // everything works If I use Branch (myBranch + x) = new Branch(i); // it doesn't x is a loop iterator, i is an int for the constructor to define an array. What am I doing wrong here.
17
3471
by: Johan Tibell | last post by:
Could someone outline the pros and cons of typedefing pointers to structs like this? typedef struct exp_ { int val; struct exp_ *child; } *exp; (This is straight from memory so it might not even compile.)
5
1283
by: Daniele M. | last post by:
Hi folks! I'm almost newbie in c++ programming, so please don't blame me :) I have a little (i hope) problem with following code and i really can't understand what i'm missing :( Hope you can help me! The following code is from my simple GUI class.
1
4766
by: radskate360 | last post by:
Hi I am newer to programming and need a bit of help with this program. OK, heres the directions. The distance between two places on earth can be calculated by using their latitudes and longitudes. The calculation for this is as follows: (The latitudes and longitudes must be converted to radians (radians=degrees * pi / 180)). PI must be set set to 20 decimals as follows: PI = 3.1419265358979323846 Earth's Radius = 3963.1
5
1567
by: robert | last post by:
Hi all, I'm trying to understand some code - u-boot 1.3rc3 - that reads data from an ethernet phy. A struct is defined as: struct mii_dev { struct list_head link; char *name; int (* read)(char *devname, unsigned char addr, unsigned char reg, unsigned short *value);
17
1231
by: mdh | last post by:
Quick question. In the code below, omitting the word "word", as in char *word, produces an error of syntax. In similar "non-struct" declarations, the expression "char *" should suffice. ( I think). Is there a reason that one needs to add this? Is this unique to structs. Thanks as usual.
0
8476
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8393
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8917
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8598
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7437
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6229
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5696
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4407
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2812
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.