473,406 Members | 2,273 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.

Pretty new to C++, please help

Hello, I am new to C++ and thus far have been able to do all the program excercises in my book, but I can't get the following program scenario to build and execute.

I am trying to calculate a salesperson's salary total, the base salary is 400$, plus a bonus of either 5% or 10% of their gross sales for that week.The standard commision is 5% but it is increased to 10% if the weekly sales total is over 1000$

# include <iostream.h>

int main ()
{
cout << "What are your total sales for the week? ";
cin >> Sales;

// do I use an if statement after the code above? So if the user inputs 1100$ it knows to give the 10% bonus? And after that, to have the total salary displayed on the screen, the 400 base salary, plus whatever the comission would be. I'm just really confused on how to program the math operations inside the if statement. PLEASE HELP! THANK YOU!

return 0;

}
Oct 8 '06 #1
3 2441
manontheedge
175 100+
math functions inside if statements are very important and pretty easy to use once you get use to how they work.

you can use an if statement, or a switch statement. An if statement for the problem would look like...

cin >> sales;

if ( sales > 1000 )
{
salary = baseSalary + ( sales * .1 )
}

else if ( sales < 1000 )
{
salary = baseSalary + ( sales * .05 )
}

the first if condition is looked at, if it's not valid, it goes to the next one. Inside of each if, you put their commision plus their base salary. The left hand side (the variable) gets the result of the operations on the right.
Oct 8 '06 #2
D_C
293 100+
Expand|Select|Wrap|Line Numbers
  1. if(sales > 1100)
  2.   commission = 0.10;
  3. else
  4.   commission = 0.05;
  5.  
  6. total = base + (commission*sales);
  7. // total = 400 + (5% or 10%)*sales
Oct 8 '06 #3
Banfa
9,065 Expert Mod 8TB
if ( sales > 1000 )
{
salary = baseSalary + ( sales * .1 )
}

else if ( sales < 1000 )
{
salary = baseSalary + ( sales * .05 )
}
This code notably results in a sales person with sales of extactly 1000 getting no bonus at all, salary is left uninitialised.
Oct 9 '06 #4

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

Similar topics

3
by: frank.baris | last post by:
I usually can figure out anything by searching the groups or the net all day, but this problem has been bugging me for awhile now. I have multiple databases, all of which have the same 2 tables,...
39
by: George Hester | last post by:
How do they do it? http://home.nycap.rr.com/foryorisonly/spoof.htm It doesn't matter where the browser is when opened. But if the browser is minimazed then it jumps to (0,0) of the screen. ...
4
by: mattgcon | last post by:
When I use a stored procedure to insert data into a table and when the Datagrid refreshes two new columns are added. The dataSet is set up with one table with NO columns defined. Please help me on...
7
by: Ed Debrot | last post by:
Nothing drives me crazier than having to look at someone's code where the indentation is sloppy. Some lines are indented 2 spaces, others 10 spaces. Sometimes there's 10 blank lines between lines...
2
by: Bob | last post by:
I'm trying to use the process class through an instance of the class. As follows, Dim MyProc as Process = Myproc.start(Filename) (where filename is a string variable having the full path of the...
4
by: MooMaster | last post by:
I'm trying to develop a little script that does some string manipulation. I have some few hundred strings that currently look like this: cond(a,b,c) and I want them to look like this: ...
3
by: Robert Dufour | last post by:
I am trying to localize a very simple web site (english and french) I have a master page and one content page for now. On the master page I have placed a Localize control On the content page I...
1
by: mbowden | last post by:
I sometimes work with more than one instance of VS2005 and recently the "pretty listing" checkbox found in the Options\Text Editor\Basic\VB Specific\ menu has been giving me fits. Sometimes the VS...
3
by: Johnny Jörgensen | last post by:
I've got a serious problem. I've got Visual Studio 2005 installed, and of course I'm using the Pretty Listing formatting function. When I start up VS, everything is fine, but after a while (which...
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
marktang
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,...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.