Building up Information using a loop and cin.

This is a discussion on Building up Information using a loop and cin. within the C++ Programming forums, part of the General Programming Boards category; I cannot seem to get the total hours and profit up, as when I enter 99 it makes the total_profit ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    1

    Building up Information using a loop and cin.

    I cannot seem to get the total hours and profit up, as when I enter 99 it makes the total_profit and total_hours become 99.

    Any help would be appreciated, I've been stuck on this for about 25 minutes.

    Here's the basic concept of the code:
    Code:
    
    	
     
     
    while (hours_parked < 99)
    
     
    	{
    
     
    	cout << 
     
     
    '\n';
    
     
    	cout << 
     
     
    "Customer" << '\t' << "Hours" << '\t' << "Charge\n";
    
     
    	cout << counter << 
     
     
    '\t' << '\t' << hours_parked << '\t' << calculateCharge(hours_parked) << '\n' << '\n';
    
     
    	counter++;
    
     
    	cin >> hours_parked;
    
     
    	cin.get();
    
     
    	}
    
     
    	total_profit = hours_parked * calculateCharge(hours_parked);
    
     
    	total_hours = hours_parked;
    
    
     
    	cout << 
     
     
    "Total Hours: " << total_hours << '\n';
    
     
    	cout << 
     
     
    "Total Profit: " << total_profit << '\n';
    
    
     
    	system(
     
     
    "pause");
    
     
    }
    
    

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,292
    Please fix the code indentation first.

    Also, it isn't just enough to say that "When I do X, Y happens". You need to say "but Z is supposed to happen"!
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  3. #3
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,648

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 13
    Last Post: 04-05-2009, 10:16 AM
  2. loop building question
    By panfilero in forum C Programming
    Replies: 8
    Last Post: 12-01-2005, 07:23 AM
  3. building/using dll's
    By bluehead in forum C++ Programming
    Replies: 1
    Last Post: 04-05-2005, 07:03 AM
  4. building pc..
    By Shadow in forum Tech Board
    Replies: 13
    Last Post: 01-08-2003, 06:53 PM
  5. Embedded for loop information.
    By nikki19 in forum C++ Programming
    Replies: 1
    Last Post: 11-15-2002, 07:40 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21