Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account

C++

#1 jfrazier Posted 04 December 2005 - 10:08 PM

jfrazier

New Member

• Member
• 2 posts
I can not get the program work properly. it suppose to .50 per hour and \$2 for parking fee.
it is suppose to use the Calculate Charge function. here is my code the program works but if you enter a odd number it will not show decimal.

#include "stdafx.h"

#using <mscorlib.dll>

using namespace System;

int _tmain()
{
int a = 2.00, // Parking Fee
int h, // number of hours parked
int x=1.00, // charged per hour
int t; // total

Console::WriteLine(S"Please enter the # of hours Parked, -1 to quit");

while (h != -1){
t= h*x/2 + 2;

Console::WriteLine(S"Your total is {0}",t.ToString());

}//end while
return 0;
}
• 0

#2 ricci Posted 05 December 2005 - 12:33 PM

ricci

Member

• Member
• 64 posts
Hi jfrazier,

Your problem is that you are using int's for everything. Int's don't calculate or store any fractional values. Try changing your variable types to double.

-Ricci
• 0

Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users