GIDForums  

Go Back   GIDForums > Computer Programming Forums > CPP / C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 21-Jan-2007, 21:46
dagiffy dagiffy is offline
New Member
 
Join Date: Jan 2007
Posts: 2
dagiffy is on a distinguished road
Question

something simple (I think)


I'm in my second week of my first year of C++ and I'm doing what I imagine is a simple assignment. I'm inputing this:

CPP / C++ / C Code:
#include <iostream>
#include <string>
#include <math.h>

using namespace std;

const double CITY_TAX = 0.095;

int main ()
{
	
	int entryHour;
	int entryMinute;
	int exitHour;
	int exitMinute;
	double entryMinutesToHours;
	double exitMinutesToHours;
	double finalEntryTime;
	double finalExitTime;
	double totalTime;
	double totalHours;
	double parkingCost;
	double totalTax;
	double totalCost;

	
    // Customer Dialogue Section
	cout << "Welcome to David Gifford's Garage" ; 
    cout << "Time of Entry(Hour): " ;											
	cin >> entryHour;
	cout << "Time of Entry(Minute): " ;
	cin >> entryMinute;
	cout << "Time of Exit(Hour): " ; 
	cin >> exitHour;
	cout << "Time of Exit(Minute): " ;
	cin >> exitMinute;
	cout << "You parked for " << totalHours << "hours." << endl;
	cout << "The parking fee is $ " << parkingCost << endl;
	cout << "The city tax is $ " << totalTax << endl;
	cout << "Your total charge is $ " << totalCost << endl;
	cout << "Thank you for using David Gifford's Garage." << endl;

	//Calculate the results of customer input    
	entryMinutesToHours = entryMinute / 60.0;
	exitMinutesToHours = exitMinute / 60.0;
	finalEntryTime = entryHour + entryMinutesToHours;
	finalExitTime = exitHour + exitMinutesToHours;
	totalTime = finalExitTime - finalEntryTime;
	totalHours = ceil (totalTime);         <---------------------------------------I think this is my error, how to fix?

	//Output the results
	parkingCost = totalHours * 2.50;
	totalTax = parkingCost * CITY_TAX;
	totalCost = parkingCost + totalTax;
	
	

	char reply;
	cout << "Enter q to quit...";
	cin >> reply;
	return 0;
	
}

and the errors I'm getting are these. Among other things, I don't believe I'm using the "ceil" thing right, but I'm supposed to take the total hours from being parked in a garage, round up to the next hour, and calculate total charge plus tax. It's 2.50 an hour, and if even 1 minute of the next hour is used, the charge is for the whole hour, so that 3hrs and 1 minute is charged 4 hours.

My errors are these:
Code:
1>------ Build started: Project: David Gifford's Garage, Configuration: Debug Win32 ------ 1>Compiling... 1>David Gifford's Garage.cpp 1>c:\cs161\david gifford's garage\david gifford's garage\david gifford's garage.cpp(43) : warning C4700: uninitialized local variable 'totalHours' used 1>c:\cs161\david gifford's garage\david gifford's garage\david gifford's garage.cpp(44) : warning C4700: uninitialized local variable 'parkingCost' used 1>c:\cs161\david gifford's garage\david gifford's garage\david gifford's garage.cpp(45) : warning C4700: uninitialized local variable 'totalTax' used 1>c:\cs161\david gifford's garage\david gifford's garage\david gifford's garage.cpp(46) : warning C4700: uninitialized local variable 'totalCost' used 1>Linking... 1>Embedding manifest... 1>Build log was saved at "file://c:\CS161\David Gifford's Garage\David Gifford's Garage\Debug\BuildLog.htm" 1>David Gifford's Garage - 0 error(s), 4 warning(s) ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
Last edited by LuciWiz : 22-Jan-2007 at 01:42. Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
  #2  
Old 21-Jan-2007, 22:10
dagiffy dagiffy is offline
New Member
 
Join Date: Jan 2007
Posts: 2
dagiffy is on a distinguished road

Re: something simple (I think)


My errors went away when I dropped the dialogue portion that used calculated values below the area where I calculated those values. Then I had to use cout << fixed; and cout << setprecision(2); and after that it worked perfectly.
 
 

Recent GIDBlog2nd Week of IA Training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
i need help with a simple program!! alfie27 CPP / C++ Forum 1 06-Oct-2006 21:29
my 1st simple program, 3 slight problems. skizer CPP / C++ Forum 11 07-Feb-2006 15:31
UpdateData - simple MFC project kobycool MS Visual C++ / MFC Forum 3 23-Oct-2005 02:45
Simple Calculator Application MOHAMMEDALI1989 Java Forum 1 06-Oct-2005 17:00
Just need one simple example or link to such example Doggonit MySQL / PHP Forum 2 31-Jul-2005 18:39

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 19:14.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.