How do i write the formula for calculating the total sales and average for this program: -
while (sales !=-1)
-
{
-
i <= 12; i++;
-
cout << fixed << setprecision(2) << "Please enter your sales for month " << i << ": ";
-
cin >> sales;
-
} //end while
-
-
i <= 12; i--;
-
cout << "For " << i++ << " months: ";
-
-
cout << fixed << setprecision(2) << "Total sales: $ " << totalSales << endl;
-
cout << fixed << setprecision (2) << "Average sales: $ " << average << endl;
-
-
Can someone help me if I'm doing the right thing here because it is giving some kind of warning but dont know why. Please help!
6 3429 -
using namespace std;
-
using std::fixed;
-
using std::setprecision;
-
No big deal, but the second two using directives are unnecessary here.
What are these two statements meant to accomplish? Are you trying to implement a for loop?
Beyond that, post the text of the warning you're getting.
Generally, you cannot use operators like ==, !=, >, <, <=, >=, etc wth floating point numbers.
Due to the automatic rounding, these operators may report a condition as true when the numbers
are only close in value.
Google for Floating Point Arithmetic or read IEEE 754 standard specification for details.
To compare two floating point numbers, you have to establish a sigma error tolerance. -
if (fabs(i - j) < 0.000001) { ... // almost equal }
-
-
using namespace std;
-
using std::fixed;
-
using std::setprecision;
-
No big deal, but the second two using directives are unnecessary here.
What are these two statements meant to accomplish? Are you trying to implement a for loop?
Beyond that, post the text of the warning you're getting.
No am not trying to implement a for loop I just want to use a while loop but I want the months to automatically just come as Month1...Month2 ...etc.
The program is giving me this warning: warning C4552: '<=' : operator has no effect; expected operator with side-effect
i <= 12 will be either true or false. That is, this will evaluate to 0 or 1. Plus the 0 or 1 is not used so the whole statement is pointless. That's the essence of the compiler warning.
i <= 12 will be either true or false. That is, this will evaluate to 0 or 1. Plus the 0 or 1 is not used so the whole statement is pointless. That's the essence of the compiler warning.
Thanks guys but i still cant get the expected results cos I do not know how to code the calculations for the total sales and average sales.......cou ld someone give me an idea on how to do that???
For starters, you have one sales variable. If you want sales by month I would expect you would need 12 sales variables. Maybe in an array. That way the 5th variable could be May.
All you have to do is display the variables. Add them up and divide by 12 and you have average monthly sales. etc...
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: RJN |
last post by:
Hi
I have a main report and a sub report. I have a formula field on the
main report and one on the sub report. I want the formula in the
subreport to be evaluated after the formula in the main report. The sub
report is called in the report header of the main report and the
formula fields are in the details section of the reports.
Main report looks something like this.
|
by: RJN |
last post by:
Hi
Sorry for posting this message again.
I have a main report and a sub report. I have a formula field on the
main report and one on the sub report. I want the formula in the
subreport to be evaluated after the formula in the main report. The sub
report is called in the report header of the main report and the
formula fields are in the details section of the reports.
Main report looks something like this.
|
by: rjn |
last post by:
Hi
I have a main report in which I have inserted a sub report. I have a formula field on the main report and one on the sub report. I want the formula in the
subreport to be evaluated after the formula in the main report. The sub
report is called in the report header of the main report and the
formula fields are in the details section of the reports.
Main report looks something like this.
Report Header
|
by: sal |
last post by:
Greets, All
Converting array formula to work with datatables/dataset tia sal
I finally completed a formula I was working on, see working code below.
I would like to change this code so it will work with a variable mutl-
row, 5 column datatable where the users select items. Anyone have any
suggestions on where to start?
Or changes in the current code that might be made.
|
by: Brian VanPelt |
last post by:
I am not a very experienced VB user, but I was trying to make a form
that a user could input a formula for summation.
For example, I would like the user to input the beginning and end
values of a counter, and also have the user input the formula to be
added up.
More explicitly, suppose a user wants to add up
1 + 1/2 + 1/3 + 1/4 + ... + 1/100
| |
by: GB |
last post by:
Hello,
How to calculate value for the following formula (I need C# code):
res = (((m+1)(m+2)...(m+(k-1)))/1.2...(k-1))
or more generalized formula is:
k-1
__
| | (m+i)
|
by: gkinu |
last post by:
Crystal Report for Visual Studio.NET 2003.
I have a formula that brings an error " .. A number is required here ... ". See the code snippet below which i have simplified. In the actual formula, the function NthLargest is being accessed in a loop hence the need to have the first parameter being a variable (pos):
numberVar pos := 1;
NthLargest (pos, {Table1.score});
This will throw an error " .. A number is required here ... ". If i...
|
by: JHaworth |
last post by:
Hi,
Please could someone point me in the right direction with a formula I am trying to create which will enable me to calculate a Net IRR for a series of data?
My Problem:
•My formula in Excel is currently too long, complicated and slow
•I am currently using the IRR function on a series of cashflows. eg =IRR(cashflow,0.01)
•I am trying to create a formula called NetIRR(cashflow, fee, hurdle, compound) which will ultimately perform...
|
by: JP Romano |
last post by:
I'm sure I'm going to kick myself for this, but I just can't get the syntax right. Perhaps I'm a wee bit fried... anyway, hopefully one of you experts can set me straight again.
All I'm trying to do is increment a value in a formula as a loop exectues through a range. I can't put it in one cell and do a fill down throughout because I'll end up with inaccurate results. When I embed the api call in an if statement, only about 75% of them...
|
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: 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: 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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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...
| |