473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

electric bill

following program is compiled with zero errors but still i am getting wrong output
can anybody find where i am wrong so as to get correct output
[PHP]#include<iostream>
using namespace std;
int main()
{
int units;
char name[20];
float cost,bill,totalbill;
cout<<"enter the name"<<endl;
cin>>name;
cout<<"read units"<<endl;
cin>>units;
if(units<=100)
{
cost=(units*60/100);
bill=cost+50;
}
else if((units>100)&&(units<=200))
{
cost=(units*80/100);
bill=cost+50;
}
else if(units>=300)
{cost=(units*90/100);
bill=50+cost;
}
if(bill>300)
{
totalbill=bill+bill*(15/100);
}
else
totalbill=bill;
cout<<"MR."<<name<<"YOUR BILL IS "<<totalbill<<"Rs only"<<endl;
return 0;


] [/PHP]
Jan 14 '07 #1
5 4586
Banfa
9,065 Expert Mod 8TB
following program is compiled with zero errors but still i am getting wrong output
can anybody find where i am wrong so as to get correct output
It is hard to help you because you have not given the input plus the expected output and the erroneous output.

However I note the following.

A lot of you arithmetic is done as integer arithmetic, for instance

cost=(units*60/100);

units is a int as is 60 and 100, if units is not a multiple of 10, say 23 you might expect the answer 13.8 but because this is integer arithmetic you will get the answer 13. You need to do floating point arithmetic. This is easy, just use floating point constants instead of integer constants

cost=(units*60.0F/100.0F);

A second error is if you examine the code you have no formula for cost if units >200 and <300.
Jan 14 '07 #2
willakawill
1,646 1GB
You have to be careful with these calculations:
cost=(units*60/100);
You will get integer division and end with zero.
Jan 15 '07 #3
Banfa
9,065 Expert Mod 8TB
You will get integer division and end with zero.
May end with 0 if units == 1 or 0 or -1
Jan 15 '07 #4
willakawill
1,646 1GB
It is hard to help you because you have not given the input plus the expected output and the erroneous output.

However I note the following.

A lot of you arithmetic is done as integer arithmetic, for instance

cost=(units*60/100);

units is a int as is 60 and 100, if units is not a multiple of 10, say 23 you might expect the answer 13.8 but because this is integer arithmetic you will get the answer 13. You need to do floating point arithmetic. This is easy, just use floating point constants instead of integer constants

cost=(units*60.0F/100.0F);

A second error is if you examine the code you have no formula for cost if units >200 and <300.
Either there is something wrong with my browser or you have used admin status to bump your reply above mine. This post was not visible to me until now.
Jan 15 '07 #5
Banfa
9,065 Expert Mod 8TB
Either there is something wrong with my browser or you have used admin status to bump your reply above mine. This post was not visible to me until now.
Well I didn't no nothing, hmmm keep an eye out and let me know if this happens again.

My broswer often fails to display the text of posts properly but always leaves page space for them.
Jan 15 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: John Bailo | last post by:
Ok, I have to give that Bill Gate credit where credit is due... I put a CD in my windos 1900 workstation. it has wm9 on it and i just instlled real player one as well. as soon as i put the cd...
14
by: Me_and_you | last post by:
From: http://evan.quuxuum.org/bgnw.html#Worth Interesting stuff. read for yourself: ---------------------- How much is Bill worth right now? We obviously do not have a full reckoning of...
20
by: Gary Manigian | last post by:
I have 2 tables, one-to-many, that contain bills of material(BOMs): tblBOM: lngBOMID (PK) strAssemblyPartNo strDescription tblBOMDetail: lngBOMDetailID (PK) lngBOMID (FK)
2
by: Thomas Jollans | last post by:
Is it possible to controll an electric circuit connected to the pc via a com or lpt port from c#? (1. I want to stick two wires into the back of my pc and "connect" them via software; 2. I want to...
1
by: Scooter | last post by:
For each <a href=http://www.scooter86.com>Electric Scooter</a> listed on this site, we offer a way to purchase; just follow the link(s) at the end of the scooter's description. Occasioinally, a...
17
by: John Bailo | last post by:
What does he do all day? Find out here: http://channel9.msdn.com/Showpost.aspx?postid=163166
3
by: kj | last post by:
I am trying to diagnose a bug in my code, but I can't understand what's going on. I've narrowed things down to this: I have a function, say foo, whose signature looks something like: int foo(...
15
by: Bjoern Schliessmann | last post by:
Hello all, I'm trying to simulate simple electric logic (asynchronous) circuits. By "simple" I mean that I only want to know if I have "current" or "no current" (it's quite digital) and the only...
1
by: =?Utf-8?B?Sm9zdWZm?= | last post by:
Hi: I've been using MSN Bill Pay for years to pay my bills. I recently decided to look into Microsoft Money as I wanted a desktop application to manage and pay my bills. I downloaded the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.