C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 6th, 2003, 12:25 PM
labohemenyc labohemenyc is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: New york
Posts: 1 labohemenyc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Help!!! My C++ assignment has a problem.

Hi,

I am doing my assignment but my program is not working well. I think that something wrong is with my for loop. I hope someone can help me fix the problem.
Thanks!!!

My program goes like this.


#include<iostream.h>
#include<iomanip.h>

#define NUM_DESTINATIONS 6


int main()

{
int total_tickets,
num_orders,
another_customer,// yes =1, no=0
another_order;// yes =1, no=0



double ticket_price[6] ={56.79, 105.69, 93.49, 155.99, 87.49, 73.99};
int city_tickets[NUM_DESTINATIONS];



int destination;


double amount,
total_amount;



cout<<setprecision(2)
<<setiosflags(ios::fixed)
<<setiosflags(ios::showpoint);

//Initialize counter and accumulator
num_orders=0;
amount=0;
total_amount=0;
total_tickets=0;



//Ask for a user
cout<<"\nDo you want to process a customer";
cout<<"\nEnter 1 for Yes or 0 for No: ";
cin>>another_customer;

while(another_customer)

{

//Ask the use if he or she wants to continue

cout<<endl;
cout<<"Do you want to process a ticket order? Enter 1 for Yes or 0 for No: ";
cin>>another_order; // yes =1, no=0


while(another_order)

{
cout<<endl;
cout<<"Enter the the number of the destination(1-6): ";


cin>>destination;
if ((destination<1) || (destination > 6))
cout<<"\nInvalid destination number entered. Please try again.";

else

{


cout<<"Enter the the number of tickets desired: ";
cin>>city_tickets[destination];


amount= ticket_price[destination-1] * city_tickets[destination];

cout<<"\nThe number of tickets sold to City "<<destination<<": "
<<city_tickets[destination];
cout<<"\nThe price of each ticket: "<<ticket_price[destination-1];
cout<<"\nThe amount of tickets sold: "<<amount;


}

total_amount+= amount;
total_tickets+=city_tickets[destination];

cout<<endl;
cout<<"Do you want to process another ticket order? Enter 1 for Yes or 0 for No: ";
cin>>another_order; // yes =1, no=0

}



for (destination=0; destination<NUM_DESTINATIONS;++destination)
{


cout<<"\n\nCity"<<setw(3)<<destination+1<<":"
<<" The total number of tickets sold:"<<setw(5)<< city_tickets[destination+1]
<<" and the total amount of tickets sold:"<<setw(5)
<< city_tickets[destination+1]*ticket_price[destination];


}




//Ask for a user
cout<<endl;
cout<<"Do you want to process another customer?"<<endl;
cout<<"Enter 1 for Yes or 0 for No: ";
cin>>another_customer;
}


cout<<"\nThe grand total of all the ticket price: "<<total_amount;
cout<<"\nThe grand total of all the ticket sold: "<<total_tickets;


return 0;

}

Reply With Quote
  #2  
Old July 6th, 2003, 12:38 PM
amit_t amit_t is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: India
Posts: 9 amit_t User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
hi ,you are defining city_tickets as a int[6] array & yet you r trying to assess city_tickets[6] element...arrays index in C/C++ starts from 0...so city_tickets[destination+1] will not be b valid when
destination = NUM_DEST - 1...

similarily this is also going to cause trouble at destination = 6...

amount= ticket_price[destination-1] * city_tickets[destination];

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Help!!! My C++ assignment has a problem.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway