RSS Forums RSS
Please support our C advertiser: Programming Forums
Views: 843 | Replies: 7
Reply
Join Date: Feb 2007
Posts: 66
Reputation: bigben09 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
bigben09 bigben09 is offline Offline
Junior Poster in Training

Program help please

  #1  
Mar 27th, 2007
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;
}
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2007
Posts: 66
Reputation: bigben09 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
bigben09 bigben09 is offline Offline
Junior Poster in Training

Re: Program help please

  #2  
Mar 27th, 2007
anyone got anything for me
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,565
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 40
Solved Threads: 977
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: Program help please

  #3  
Mar 27th, 2007
QUOTE=bigben09;335365]anyone got anything for me[/quote]
don't be so impatient. I'm watching TV (House) at the moment

>> cin >> movie;
don't use that. use getline() function instead

when move is std::string
getline(cin, movie);

or when movie is char array
cin.getline( movie, sizeof(movie));
Last edited by Ancient Dragon : Mar 27th, 2007 at 11:04 pm.
<<Freelance Programmer>> << Hobby Site>>
Signature links for sale. PM me for details
Reply With Quote  
Join Date: Feb 2007
Posts: 66
Reputation: bigben09 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
bigben09 bigben09 is offline Offline
Junior Poster in Training

Re: Program help please

  #4  
Mar 27th, 2007
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;
}
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,565
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 40
Solved Threads: 977
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: Program help please

  #5  
Mar 27th, 2007
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.
<<Freelance Programmer>> << Hobby Site>>
Signature links for sale. PM me for details
Reply With Quote  
Join Date: Feb 2007
Posts: 66
Reputation: bigben09 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
bigben09 bigben09 is offline Offline
Junior Poster in Training

Re: Program help please

  #6  
Mar 27th, 2007
where does the sprintf() go i have never used that or seen that before I am new and just learning the ropes.
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,565
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 40
Solved Threads: 977
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: Program help please

  #7  
Mar 28th, 2007
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;
<<Freelance Programmer>> << Hobby Site>>
Signature links for sale. PM me for details
Reply With Quote  
Join Date: May 2006
Posts: 2,794
Reputation: WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold 
Rep Power: 16
Solved Threads: 232
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Maven

Re: Program help please

  #8  
Mar 29th, 2007
Originally Posted by bigben09 View Post
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.
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough.
-- Pearl Williams
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 4:48 am.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC