I am a C++ beginner and I am working on a C++ project that calucates the phone bill.
I got stuck on how to make every 60 minutes into one hour.. Like if the user enter 1000 (10:00) and it asks for the length of your phone call, if the user enters 70, the program has to print out the result time (end_time) 1110
here's my program, hope you guys can help me out!!
Thanks alot! - #include<iostream.h>
-
-
main()
-
{
-
int start_time;
-
int length;
-
int end_time;
-
double gross_cost ;
-
double length_discount ;
-
double total_discounts ;
-
double tax;
-
double net_cost;
-
double time_discount;
-
int length_min, length_hour;
-
int end_min, end_hour;
-
int call_hour, call_min;
-
-
cout << "What was the start time of your phone call? Write as 1900 instead of 7:00 PM\n";
-
cin >> start_time;
-
-
-
//Any call started at or after 7:00 P.M. (1900 hours) but before 8:00 A.M. (0800 hours) is discounted 60 percent.
-
-
-
if (start_time >= 1900 || start_time <= 800)
-
{
-
time_discount = (length * 0.25) * 0.6;
-
}
-
-
//Asking for the length.
-
cout << "What was the length of your phone call in minutes?\n";
-
cin >> length;
-
-
//make time look nice
-
length_min = length % 100;
-
length_hour = length / 100;
-
-
call_min = start_time % 100;
-
call_hour = start_time / 100;
-
-
end_hour = call_hour + length_hour;
-
-
end_min = call_min + length_min;
-
-
-
if (end_min >= 60)
-
{
-
end_hour++;
-
}
-
-
end_time = (call_hour + length_hour) * (100) + end_min;
-
-
-
//Any call at least 20 minutes long receives a 30 percent discount on its cost (after any other discount is subtracted).
-
-
gross_cost = length * 0.25;
-
-
if(length >=20)
-
{
-
length_discount = 0.3 * (gross_cost - time_discount);
-
}
-
-
// if time doesn't apply
-
else(length <=21);
-
{
-
length_discount = 0.3 * gross_cost;
-
}
-
-
-
//calculations
-
end_time = start_time + length;
-
total_discounts = time_discount + length_discount;
-
gross_cost = length * 0.25;
-
time_discount = gross_cost * 0.6;
-
gross_cost = total_discounts + (tax + net_cost);
-
tax = (gross_cost - total_discounts) * 0.08;
-
net_cost = gross_cost + tax - total_discounts;
-
-
// Print the result.
-
cout << "Start Time: " << start_time << '\n';
-
cout << "End Time: " << end_time << '\n';
-
cout << "Length: " << length << '\n';
-
-
cout.unsetf(ios::scientific);
-
-
cout << "Gross Cost: " << length * 0.25 << '\n';
-
cout << "Time Discount: " << (length * 0.25) * 0.6 << '\n';
-
cout << "Length Discount: " << length_discount << '\n';
-
cout << "Total Discounts: " << time_discount + length_discount << '\n';
-
-
cout << "Tax: " << (length * 0.25) - (time_discount + length_discount) * 0.08 << '\n';
-
cout << "Net Cost: " << (length * 0.25) + tax - total_discounts << '\n';
-
return 0;
-
}
5 1892 Ganon11 3,652
Recognized Expert Specialist
It looks like lines 34-51 are where you've tried to 'make the time look nice'. Can you explain to us what's not working with that section, what is working, what you were trying to do, etc.
By the way, two notes. First, <iostream.h> is a deprecated header file that has been replaced by <iostream>, so you should be using #include <iostream>. Second, when you write main(), you're implicitly writing void main(), which is non standard and almost 95% of the time will give you errors. Instead use int main(), and return 0; at the end of your program. Not much of a difference to you, but your code will now universally work.
gpraghuram 1,275
Recognized Expert Top Contributor
Hi,
One change in the code.... -
if (start_time >= 1900 || start_time <= 800)
-
{
-
time_discount = (length * 0.25) * 0.6;
-
}
-
cout << "What was the length of your phone call in minutes?\n";
-
cin >> length;
-
This should be after the code where you ask the user to enter the length like this -
cout << "What was the length of your phone call in minutes?\n";
-
cin >> length;
-
-
if (start_time >= 1900 || start_time <= 800)
-
{
-
time_discount = (length * 0.25) * 0.6;
-
}
-
I wil spend some more time in the logic and mail u back if i find something
Thanks
Raghuram
gpraghuram 1,275
Recognized Expert Top Contributor
I have made some code changes and i am posting the same.
Thanks
Raghuram
-----------------
Thanks for telling me those things.....So do you mean that I should always use <iostream> instead of <iostream.h> when writing a program? I know that void main () returns no value whereas main() and int main() returns the value zero... Because some of the sample programs in my textbook use main() so I got it mixed with int main() and void main().. Anyways, thank you!! I learned a lot today!
Hi Raghuram!
Thank you for correcting my program..
I got it!!
This program must be easy for you but hard for me!!
thanks,
Claire
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: los |
last post by:
Hi,
I'm trying to create a program similar to that of Google's desktop that
will crawl through the hard drive and index files. I have written the
program and as of now I just put the thread to sleep for 1 second after
indexing a couple of files.
I'm wondering if anyone knows of a way that I could make so that the
program will run at full speed only runs after the computer has been
idle for a while. I've looked at the "nice" command...
|
by: Stuart |
last post by:
Hi all,
I have a problem that I just cannot figure out for the
life of me.
I am trying to set up a database that contains time slots
(6 X 4hr periods to cover the day) starting from 00:00:00 -
03:59:59 etc etc etc.
DB Fields look like this
|
by: Charles Law |
last post by:
Hi guys
I have a time critical process, running on a worker thread. By "time
critical", I mean that certain parts of the process must be completed in a
specific time frame. The time when the process starts is not especially
important, but it must be complete within a small number of seconds.
The operations I am performing do not take a long time (hundreds of
milliseconds), but as each part of the process is complete, my worker thread...
|
by: Patrick Kowalzick |
last post by:
Dear all,
I just wondered if it is possible to count the number of classes created via
a template class at compile time.
To show what I mean I post an example, which is not working but carries the
idea:
static int counter = 0; // this variable can be changed only at runtime...
template <typename T> struct want_to_be_counted;
|
by: Erich Schreiber |
last post by:
In the Python Library Reference the explanation of the time.sleep()
function reads amongst others:
> The actual suspension time may be less than that requested because
> any caught signal will terminate the sleep() following execution
> of that signal's catching routine. Also, the suspension time may
> be longer than requested by an arbitrary amount because of the
> scheduling of other activity in the system.
I don't understand the...
| |
by: Russ |
last post by:
I'm interested in setting up a web page where live data can be
displayed in real-time on the web page.
For example: I would like to display a (nice looking) graph of some
data value versus time and have the graph update every second without
the user having to do anything like hit a refresh button. The data to
plot is readily available from an application running on the server - I
can expose it in whatever way is needed (currently easily...
|
by: vashwath |
last post by:
Might be off topic but I don't know where to post this question.Hope
some body clears my doubt.
The coding standard of the project which I am working on say's not to
use malloc.When I asked my lead(I have just started working) he said we
should not use dynamic allocation in real time systems, the code will
not run in predictable time period.Can anybody tell what does he
mean?Why the execution time becomes unpredictable?
Thanks
|
by: Ray Tomes |
last post by:
Hi Folks
I am an old codger who has much experience with computers
in the distant past before all this object oriented stuff.
Also I have loads of software in such languages as FORTRAN
and BASIC, QBASIC etc that is very useful except that it
really doesn't like to run on modern operating systems and
has hopeless graphics resolution and lack of ease of use in
some ways.
|
by: Maurice |
last post by:
Hi all,
I have an application, designed in Visual Studio 2005, which will run
mainly on Windows XP computers.
If I run the application on a Windows XP computer having the Windows XP
Theme selected the controls look nice rounded, etc. just like in Windows
XP.
But if I run the application on a Windows XP computer having the Windows
|
by: Ryan |
last post by:
Hello everyone,
Here is what I would like to accomplish, I have a webpart 'portal'
where each webpart is in an updatepanel. I would like the page to load
and the webparts to load as they become available.
Currently, the page renders after all controls/webparts are loaded.
Then when there are postbacks, the updatepanels work great. Is there a
way to do this with theses controls (built-in ajax.net type stuff) or
will I need to finally...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |