View Single Post
Old 09-19-2007, 09:41 PM   #1 (permalink)
zero2
Junkie
 
zero2's Avatar
 
[C++] Problem with for-loop

I have a problem for my class, and I've run into a really weird problem.

So the problem is a travel expense problem, where I need to use a for-loop to ask the user a few questions, such as cost of hotel, cost of parking fee, cost of bridge toll.

So anyhow here's a snippet of my code:

Code:
#include <iostream>
using namespace std;

int main()
{
double dhotel, dmeal, dpark, dbridge, dmiles, dtemp = 0.0; 
	string scar; // Car name
	int iyear; // Car year
	string scolor; // Car color
	string smake; // Car make
	int i = 0;
	int iSize = 0;
	int iCounter = 0;

/* = = = = = = = = = = = = = = = = = = = = = = = = = = = =	*/	
	cout << "Enter number of hotels you visited: ";
	cin >> iSize;

	for ( i = 0; i < iSize; i++ )
	{
		iCounter++;
		cout << "\nEnter total cost of hotel "
				 << iCounter
				 << ": $ ";
		cin >> dtemp;
		dhotel += dtemp;
	}
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = =	*/
cout << "\nTotal cost of hotel: $ "
			<< dhotel;

	return 0;
}
Output
--------
Enter number of hotels you visited: 2

Enter total cost of hotel 1: $ 1.00

Enter total cost of hotel 2: $ 1.00

Total cost of hotel: $ 0.00162506 What's going on here?
zero2 is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73