Hello and thanks for reading my post. I need help converting the fallowing Algorithm into working C++ code, and below is what i have come up with so far, what do i need to do to make this compile?

Algorithm:

PayCalc

1. CaseOf
PayCode = "H"
Pay = Rate * Hours
Paycode = "P"
Pay = Rate
Paycode = "C"
Pay = Commission * Sales
Paycode = "S"
Pay = Salary

EndOfCase

2. Exit

Code:

#include <iostream>
using namespace std;
int main()
{
char H, P, C, S, paycode;
double paycode_h, paycode_p, paycode_c, paycode_s, rate, hours, pay, commission, sales, salary;
cout << "Enter Your Paycode (H,P,C,S).";
cin >> paycode;
switch(paycode)

{

case 'H':
cout << "Pay = Rate * Hours" << endl;
cin << paycode_h;
case 'P':
cout << "Pay = Rate * NoPieces" << endl;
cin << paycode_p;
break;
case 'C':
cout << "Pay = Commission * Sales" << endl;
cin << paycode_c;
break;
case 'S':
cout << "Pay = salary"<< endl;
cin << paycode_s;
break;
default:
cout << "You must enter a valid Paycode" << endl;


}
return 0;
}

Thank You!

Here is a good resource on the switch/case/default statement( s )
http://msdn.microsoft.com/en-us/library/66k51h7a(VS.80).aspx

So, in your situation, you should treat the choices as characters.

int main(void)
{
	char chrChoice = 'h';
	double pay = 0;
	double rate = 35.0;
	double hours = 8;

	switch(chrChoice)
	{
		case 'h' : pay = rate*hours;
			break;

		default:
			break;
	}

	printf("Pay=%1.02f", pay);

	return 0;
}

Hello and thanks for reading my post. I need help converting the fallowing Algorithm into working C++ code, and below is what i have come up with so far, what do i need to do to make this compile?

Level A: A1 = Zmed - Zmin
A2 = Zmed - Zmax
if A1 > 0 AND A2 < 0, go to level B
else increase the window size
if window size < Smax, repeat level A
else output Zxy
Level B: B1 = Zxy - Zmin
B2 = Zxy - Zmax
if B1 > 0 AND B2 < 0, output Zxy
else output Zmed

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.