Need some changes with a function (C++)

Hi! I 'm new here. Well, i have some problems with my code. First of all, i speak spanish, so i might need to apologize if my english is not very good (also some parts of the code is in spanish but i'll translate most of the code with the problem). Ok, It seems like the code its working and all, but in the console when it is asking "Everything ok , do you want to continue?" i press 1 and it does not show the "Enter the employee 's salary," again , it prints the results of the function planilla , another thing , it does not calculate anything. For example: igss = 500 + a * 0.0483, it needs to be 24.2949 if i insert 3 for the salary, but in the console shows 500, and the other process in function doesn't works too! "... Please, anyone would give me the solution for my code? I will thank you!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <iostream>
#include <conio.h>
#include <windows.h>
using namespace std;

//FUNCTION PLANILLA
void planilla(int a){

float counter;
float liquido;
float descuentoTotal;
float igss;
int i;

//COUNTER OF THE EMPLOYEE'S ENTRY'S.
	for (i=0; i<=a; i++);{
	counter = i;
   }

//PROCESS
   descuentoTotal = 500+a*0.0983;
   igss = 500+a*0.0483;
   liquido = 500-descuentoTotal;


//PRINTS THE RESULTS OF THE PROCESS

	textcolor(15);
	gotoxy(24,11); cprintf("EMPLOYEE'S ENTRY'S "); cout << counter;
   textcolor(15);
	gotoxy(24,13); cprintf("Liquido total: "); cout << liquido;
   textcolor(15);
	gotoxy(24,15); cprintf("Descuentos total: "); cout << descuentoTotal;
   textcolor(15);
	gotoxy(24,17); cprintf("IGSS total: "); cout << igss;

}

int sueldo;    //GLOBAL INT VARIABLES
int opcion;
int sueldoNuevo;

int main(){

gotoxy(24,4); cprintf("Acumulo las planillas para ti");
textcolor(15);
gotoxy(24,6); cprintf("Enter the employee's salary: ");
cin >> sueldo;
textcolor(15);
gotoxy(24,8); cprintf("Everything ok, do you want to continue?");
textcolor(15);
gotoxy(24,9); cprintf("1 = Yes, 2 = No ");
cin >> opcion;
if (opcion == 1){
while (opcion != 1){
clrscr();
//IF OPCION IS 1, PRINTS THE HEADER AGAIN WITH A WHILE
gotoxy(24,4); cprintf("Acumulo las planillas para ti");
textcolor(15);
gotoxy(24,6); cprintf("Enter the employee's salary ");
cin >> sueldoNuevo;
sueldo = sueldo+sueldoNuevo;
planilla (sueldo);
textcolor(15);
gotoxy(24,8); cprintf("Everything ok, do you want to continue?");
textcolor(15);
gotoxy(24,9); cprintf("1 = Yes, 2 = No ");
cin >> opcion;
}
}

//CALL FUNCTION PLANILLA
planilla (sueldo);

getch();
return 0;
}
Last edited on
I am not sure to understand why you ask salary and why you calculate a discount , but try this .
Maybe you can tell us what you want exactly to calculate . Use google traduccion if you are not sure :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//FUNCTION PLANILLA
void planilla(int itemPrice){

double liquido = 0.0;
double descuentoTotal = 0.0;
double igss = 0.0;


//PROCESS
   descuentoTotal = itemPrice * 0.0983;//discount?
   igss = itemPrice * 0.0483;//tax ?
   liquido = itemPrice + descuentoTotal - igss;


//PRINTS THE RESULTS OF THE PROCESS

	system("color 15");
	gotoxy(24,11); cprintf("EMPLOYEE'S ENTRY'S "); cout << itemPrice;
   system("color 15");
	gotoxy(24,13); cprintf("Liquido total: "); cout << liquido;
   system("color 15");
	gotoxy(24,15); cprintf("Descuentos total: "); cout << descuentoTotal;
   system("color 15");
	gotoxy(24,17); cprintf("IGSS total: "); cout << igss;

}


I had to change some code because it was not working in Visual Studio.
Oh my, thanks to you i found the solution. I'm asking the salary to calculate the tax of my country, thats it. I was doing something bad here:

descuentoTotal = 500+a*0.0983;

And now thanks to you, it needs to be:

descuentoTotal = (500+a)*0.0983;

Thats why the process wasn't doing a good job. Now i got the problem with the options, because i press 1 in the "Do you want to continue" part and it doesn't show again the "Enter the employee's salary:" part because it needs to be a cicle, can you find the problem there?
ok I can check.
try this :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
int main(){

	gotoxy(24,4); cprintf("Acumulo las planillas para ti");
	system("color 15");
	gotoxy(24,8); cprintf("Everything ok, do you want to continue?");
	system("color 15");
	gotoxy(24,9); cprintf("1 = Yes, 2 = No ");

	cin >> opcion;
	system("cls");
	while(opcion == 1)
	{
		gotoxy(24,4); cprintf("Acumulo las planillas para ti");
		system("color 15");
		gotoxy(24,6); cprintf("Enter the employee's salary ");
		cin >> sueldoNuevo;
		sueldo = sueldo+sueldoNuevo;
		planilla (sueldo);
		
		getch();
		system("cls");
		gotoxy(24,8); cprintf("Everything ok, do you want to continue?");
		system("color 15");
		gotoxy(24,9); cprintf("1 = Yes, 2 = No ");
		cin >> opcion;
		system("cls");
	}

//CALL FUNCTION PLANILLA
//planilla (sueldo);

getch();


return 0;
}
OMG! Ericool Thank you so much !! Sorry for being a noob, i'm just starting to learn it ( c ++ ) because i'm studying systems engineering. Really, thanks for giving me the solution!
you're welcome. :)
Topic archived. No new replies allowed.