Hey I want to be able to put a movie title in the is more than one world and it goes crazy when i do, if you run my program and enter one word when it asks for the movie title it will work fine. but when u enter a more than one word (using space) it goes crazy and ends the program. what do i need to do.

#include "stdafx.h"
#include <iostream>
#include <ctype.h>
using namespace std;
int main()
{
 char movie[50];
 int adult_ticket_price, child_ticket_price;
 int adult_ticket_sold, child_ticket_sold;
 int percentage_of_gross_amount_donated;
 
 cout <<"Enter The Movie Name: ";
 cin >> movie;
 cout << "";
 cout <<"Enter The Adult Ticket Price: $";
 cin >> adult_ticket_price;
 cout << "";
 cout <<"Enter The child ticket price: $";
 cin >> child_ticket_price;
 cout << "";
 cout <<"Enter The Number of Adult Tickets Sold: ";
 cin >> adult_ticket_sold;
 cout << "";
 cout <<"Enter The Number of Child Tickets Sold: ";
 cin >> child_ticket_sold;
 cout << "";
 cout <<"Enter The Percentage of Gross Amount Donated: ";
 cin >> percentage_of_gross_amount_donated;
 cout << "";
 cout <<"Number of Tickets Sold: " << ((adult_ticket_sold)+(child_ticket_sold))<< endl;
 cout <<"Gross Amout is: $" << (((adult_ticket_sold)*(adult_ticket_price))+((child_ticket_sold)*(child_ticket_price))) << endl;
cout <<"Amount Donated is: $" << ((((adult_ticket_sold)*(adult_ticket_price))+((child_ticket_sold)*(child_ticket_price)))*((percentage_of_gross_amount_donated)*(.01)));
 cout <<" "<<endl;
 return 0;
}

anyone got anything for me

anyone got anything for me

don't be so impatient. I'm watching TV (House) at the moment

cin >> movie;

don't use that. use getline() function instead

when movie is std::string

getline(cin, movie);

or when movie is char array

cin.getline( movie, sizeof(movie));

thanks man i got that to work. now if you could help me with one last thing, when it prints out the gross amout of money and the donated amout of money i need it to print out 2 decemal places. for example 100.00 or 100.34, either way i need to see 2 decimale places you got anything for me on that one. sometimes it prints out 1 decimal place and sometimes 3. what can I do.

#include "stdafx.h"
#include <iostream>
#include <ctype.h>
using namespace std;
int main()
{
 char movie[50];
 float adult_ticket_price, child_ticket_price;
 float adult_ticket_sold, child_ticket_sold;
 float percentage_of_gross_amount_donated;
 
 cout <<"Enter The Movie Name: ";
 cin.getline( movie, sizeof(movie)); 
 cout << "";
 cout <<"Enter The Adult Ticket Price: $";
 cin >> adult_ticket_price;
 cout << "";
 cout <<"Enter The child ticket price: $";
 cin >> child_ticket_price;
 cout << "";
 cout <<"Enter The Number of Adult Tickets Sold: ";
 cin >> adult_ticket_sold;
 cout << "";
 cout <<"Enter The Number of Child Tickets Sold: ";
 cin >> child_ticket_sold;
 cout << "";
 cout <<"Enter The Percentage of Gross Amount Donated: ";
 cin >> percentage_of_gross_amount_donated;
 cout << "";
 cout <<"Number of Tickets Sold: " << ((adult_ticket_sold)+(child_ticket_sold))<< endl;
 cout <<"Gross Amout is: $" << (((adult_ticket_sold)*(adult_ticket_price))+((child_ticket_sold)*(child_ticket_price))) << endl;
 cout <<"Amount Donated is: $" << ((((adult_ticket_sold)*(adult_ticket_price))+((child_ticket_sold)*(child_ticket_price)))*((percentage_of_gross_amount_donated)*(.01)));
 cout <<" "<<endl;
 return 0;
}

try setw() or setprecision() in <iomanip> header file. There may be other ways I don't know. I like sprintf() for that better because its easier to use.

where does the sprintf() go i have never used that or seen that before I am new and just learning the ropes.

here is an example. but maybe someone else can tell you how to do it with c++ instead of sprintf

float n = 123.456789;
char buf[20];
// format for 2 decimal places
sprintf(buf,"%3.2f", buf);
cout << buf;

where does the sprintf() go i have never used that or seen that before I am new and just learning the ropes.

Since you're using C++, might as well stick with setw And hasn't anyone mentioned code formatting yet? You need to indent your code so we can follow it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.