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<iostre am>
using namespace std;
int main()
{
int units;
char name[20];
float cost,bill,total bill;
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."<<na me<<"YOUR BILL IS "<<totalbill<<" Rs only"<<endl;
return 0;
] [/PHP]
5 4597 Banfa 9,065
Recognized Expert Moderator Expert
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.
You have to be careful with these calculations:
cost=(units*60/100);
You will get integer division and end with zero.
Banfa 9,065
Recognized Expert Moderator Expert
You will get integer division and end with zero.
May end with 0 if units == 1 or 0 or -1
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.
Banfa 9,065
Recognized Expert Moderator Expert
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 in, wm9 fired up and started playing, meanwhile
rp1 was also /trying/ to start up and then finally did and asked me some
stupid question about my /media library/.
by that time, i was 30 seconds into the first song...so of course I shut
|
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 everything Bill owns. But,
according to the Yahoo! Insider Trades site, Bill has 1,077,499,336 shares
of MSFT.
This figure reflects all trades made through Nov/04/30, which is the most
|
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)
|
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 send electricity
with a specific voltage through one of them to see if they are connected
on the other end.) Or is it posible with the win32 api?
|
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 member of the online
electric scooter group offers a scooter for sale.China <a
href=http://www.scooter86.com>Gas Scooter</a> catalog and gas scooter
manufacturer directory. Trade platform for China gas scooter manufacturers
and global gas scooter...
| |
by: John Bailo |
last post by:
What does he do all day?
Find out here:
http://channel9.msdn.com/Showpost.aspx?postid=163166
|
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( int w, int x, int y, int z, my_struct **results )
During its execution, foo initializes *results using calloc:
( *results ) = calloc( w+1, sizeof( my_struct ) );
|
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
elements need to be (with some level of abstraction to my specific
problem)
- sources (here begin currents)
- ground (here end currents)
|
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 trial and set things up. Everything worked fine until I
got to the point of adding MSN Bill Pay as an account. I was able to add it
but when it came time to access it, I couldn't figure out where to go within
MSN Bill Pay to have it give me a PIN or...
|
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: 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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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: 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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |