Friday, July 31, 2009

Need help with code (C++)?

ok here it is... my problem is this...


I can type in the name to the movie which is two words ( Death Grip)


but then when i want to put the adult tickets in its always accompanied by children too...


whats weird is if my movie name is one name like (Death)


then i can seperately imput adults and children.


WHAT DO I DO? heres my code. dont just tell me...


please acually write it out for me.... im learning still





thanks





#include %26lt;cstdlib%26gt;


#include %26lt;iostream%26gt;





using namespace std;





int main(int argc, char *argv[])


{


cout %26lt;%26lt; "This program was written by Jacob A. DePratti" %26lt;%26lt; endl;


cout %26lt;%26lt; " " %26lt;%26lt; endl;


string name[50];


string adult;


string child;


cout %26lt;%26lt; "Enter the movie's Name: ";


cin %26gt;%26gt; name[50];


cout %26lt;%26lt; "Enter the number of adult tickets sold:" %26lt;%26lt; endl;


cin %26gt;%26gt; adult;


cout %26lt;%26lt; "Enter the number of child tickets sold:" %26lt;%26lt; endl;


cin %26gt;%26gt; child;


cout %26lt;%26lt; " " %26lt;%26lt; endl;


cout %26lt;%26lt; "***************************************... %26lt;%26lt; endl;


cout %26lt;%26lt; "" %26lt;%26lt; endl;


cout %26lt;%26lt; " INCOME STATEMENT" %26lt;%26lt; endl;


cout %26lt;%26lt; " ****************" %26lt;%26lt; endl;


cout %26lt;%26lt; "" %26lt;%26lt; endl;


cout %26lt;%26lt; "Movie Name: " "Death Grip" %26lt;%26lt; endl;


cout %26lt;%26lt; "Adult Tickets Sold: " "382" %26lt;%26lt; endl;


cout %26lt;%26lt; "Child Tickets Sold: " "127" %26lt;%26lt; endl;


cout %26lt;%26lt; "Gross Box Office Profit: ""$" "2673.00" %26lt;%26lt; endl;


cout %26lt;%26lt; "Net Box Office Profit: ""$" "534.60" %26lt;%26lt; endl;


cout %26lt;%26lt; "Amount Paid To Distributer: ""$" "2138.40" %26lt;%26lt; endl;





cout %26lt;%26lt;""%26lt;%26lt; endl;


cout %26lt;%26lt;""%26lt;%26lt; endl;


cout %26lt;%26lt;""%26lt;%26lt; endl;


cout %26lt;%26lt;""%26lt;%26lt; endl;

















system("PAUSE");


return EXIT_SUCCESS;


}

Need help with code (C++)?
umm..





string name[50] isn't an array so just make it





string name





I think you got that confused with char arrays which would be





char name[50]





also you should add





const double adultTicketPrice





const double childTicketPrice
Reply:Change:


string name[50];


string adult;


string child;


cout %26lt;%26lt; "Enter the movie's Name: ";


cin %26gt;%26gt; name[50];


cout %26lt;%26lt; "Enter the number of adult tickets sold:" %26lt;%26lt; endl;


cin %26gt;%26gt; adult;


cout %26lt;%26lt; "Enter the number of child tickets sold:" %26lt;%26lt; endl;


cin %26gt;%26gt; child;





To this:


string name;


int adult, child;


cout %26lt;%26lt; "Enter the movie's Name: ";


getline(cin, name);


cout %26lt;%26lt; "Enter the number of adult tickets sold:" %26lt;%26lt; endl;


cin %26gt;%26gt; adult;


cout %26lt;%26lt; "Enter the number of child tickets sold:" %26lt;%26lt; endl;


cin %26gt;%26gt; child;
Reply:The guy above is right, but he's missing the point.





A space counts as a separator. So if you put in two words ("Death grip"), then "death" goes into name and "grip" goes into adult. Then whatever you thought you put into adult goes into child and then you're done with inputs. To fix this, read the whole line into the string like so.





Replace the string name[50] and the cin%26gt;%26gt;name[50] with this:





string name;


getline(cin,name);











BTW this section of code will output the same thing everytime:





cout %26lt;%26lt; "Movie Name: " "Death Grip" %26lt;%26lt; endl;


cout %26lt;%26lt; "Adult Tickets Sold: " "382" %26lt;%26lt; endl;


cout %26lt;%26lt; "Child Tickets Sold: " "127" %26lt;%26lt; endl;


cout %26lt;%26lt; "Gross Box Office Profit: ""$" "2673.00" %26lt;%26lt; endl;


cout %26lt;%26lt; "Net Box Office Profit: ""$" "534.60" %26lt;%26lt; endl;


cout %26lt;%26lt; "Amount Paid To Distributer: ""$" "2138.40" %26lt;%26lt; endl;





I think you wanted to write a program to output whatever you inputted. Try this:





cout %26lt;%26lt; "Movie Name: "%26lt;%26lt;name%26lt;%26lt; endl;


cout %26lt;%26lt; "Adult Tickets Sold: "%26lt;%26lt;adult %26lt;%26lt; endl;


cout %26lt;%26lt; "Child Tickets Sold: "%26lt;%26lt;child%26lt;%26lt; endl;





note that I replace the specific values with the variable name instead. For the other stuff outputted (like gross sales), I can't tell you how to do that because I don't know all the info, but I trust you can do it.

sound cards

No comments:

Post a Comment