473,395 Members | 2,151 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,395 software developers and data experts.

Else/Else if statement for pay program

How do I write a program which computes weekly pay for employees with the following characteristics? The program should accept a pay ray and the number of hours worked. The output should be the amount of money the employee earned. Note that when an employee works more than 40 hours per week, they earn one and a half times their normal pay. If the user enters any inappropriate values, the program should output an appropriate error message. So far I have...

#include <iostream>
#include <string>
using namespace std;
void main(void)
{
string pRate;
string hours;
string pay;

cout << "Enter number of hours worked: " << endl;
cin >> hours;

cout << "Enter your pay rate: " << endl;
cin >> pRate;

pay = hours * pRate;

if(


}
Sep 29 '11 #1
3 2266
whodgson
542 512MB
if hours are > 40 prate for these extra hours = prate *1.5
So....
pay=hours*prate + if(hours>40)(hours-40)*(prate*1.5)
Sep 29 '11 #2
Banfa
9,065 Expert Mod 8TB
whodgson, your formula is wrong consider 50 hours at £10 per hour (or $ if you wish)

First 40 hours at £10 = £400
Next 10 hours at £10 * 1.5 = £150
Total £550

But your formula gives 50 * 10 + ((50 - 40) * (10 * 1.5))
= 500 + (10 * 15)
= 650
Sep 29 '11 #3
whodgson
542 512MB
yes Banfa your perspicacity is absolutely impeccable and i tried very hard to get it right... so the formula should have been:
Expand|Select|Wrap|Line Numbers
  1. if(hours<=40)pay=hours*prate;
  2. else if(hours>40)pay=40*prate + (hours-40)* (prate*1.5);
  3. else cout<<"under 40 hours requires a doctor's certificate!";
.....more attention to detail needed!
Sep 30 '11 #4

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

Similar topics

33
by: Diez B. Roggisch | last post by:
Hi, today I rummaged through the language spec to see whats in the for ... else: for me. I was sort of disappointed to learn that the else clauses simply gets executed after the loop-body -...
27
by: Ron Adam | last post by:
There seems to be a fair amount of discussion concerning flow control enhancements lately. with, do and dowhile, case, etc... So here's my flow control suggestion. ;-) It occurred to me (a...
4
by: Scott | last post by:
I insert a number into textbox1 between the number of 1 and 37 and i need to manipulate what the user puts in. For instance if they put between 1 and 5 they get a certain price and between 6...
18
by: swaroophr | last post by:
Which of switch statement and if-else statement takes less time to execute?
5
by: Brie_Manakul | last post by:
Is there a way in javascript to do an if else that shows a script in an iframe? Let me know if that doesn't make sense. We have a portal and in a portlet I need to grab these javascript links to...
4
by: Brie_Manakul | last post by:
I need to set up an if else to show different weather scripts based on the city selection they choose. Any help on this would be great. Thanks! <%@ page language="java" import="java.util.*,...
2
by: paul | last post by:
Hi all, I've been handed some code and, unless I've got the numbering of parentheses wrong, one of the functions has a curious if-else statement. The thing compiles but is it right? I know the...
25
by: metaperl.etc | last post by:
A very old thread: http://groups.google.com/group/comp.lang.python/browse_frm/thread/2c5022e2b7f05525/1542d2041257c47e?lnk=gst&q=for+else&rnum=9#1542d2041257c47e discusses the optional "else:"...
1
by: kenneth6 | last post by:
#include <iostream> using namespace std; int main() { char firstname; char finalFirstname; cout << "Enter your first name: "; int num = 0;
5
by: david bonsall | last post by:
I have a field called and the value of that field can be deciphered into a location for that client. Eg. SU023 = UK SA024 = Australia ....so SUR023023 = UK, whereas SUT024076 =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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,...

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.