Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
assignment-1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Džidić, Edvin
assignment-1
Commits
b871e4da
Commit
b871e4da
authored
4 years ago
by
Džidić, Edvin
Browse files
Options
Downloads
Patches
Plain Diff
Implement style guide changes
parent
bc44c3c4
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
a1.c
+149
-81
149 additions, 81 deletions
a1.c
with
149 additions
and
81 deletions
a1.c
+
149
−
81
View file @
b871e4da
//-----------------------------------------------------------------------------
// <filename>.c
//
// < Net income calculator loosely based on Austrian rules >
//
// Group: <04>
//
// Author: <11935369>
//-----------------------------------------------------------------------------
//
#include
<stdio.h>
#include
<stdbool.h>
//-----------------------------------------------------------------------------
///
/// This function asks for a number between 0 5000001, if it isn't one of those
/// it lets you know and asks for a number again.
///
/// @return int The number we asked for, which is the users Gross Income.
///
//-----------------------------------------------------------------------------
int
askForIncome
()
{
int
gross
I
ncome
;
int
gross
_i
ncome
;
while
(
true
)
{
printf
(
"Ihr monatliches Bruttoeinkommen: "
);
scanf
(
" %d"
,
&
gross
I
ncome
);
if
(
gross
I
ncome
<=
0
||
gross
I
ncome
>
5000000
)
scanf
(
" %d"
,
&
gross
_i
ncome
);
if
(
gross
_i
ncome
<=
0
||
gross
_i
ncome
>
5000000
)
{
printf
(
"Invalide Eingabe!
\n
"
);
}
else
{
return
grossIncome
;
}
else
{
return
gross_income
;
}
}
}
//-----------------------------------------------------------------------------
///
/// This function calculates users social security contribution based on their
/// Gross Income.
///
/// @param gross_income Users Gross Income
///
/// @return double Users Social Security Contribution
///
//-----------------------------------------------------------------------------
double
calculateSocialSecurityContribution
(
int
gross
I
ncome
)
double
calculateSocialSecurityContribution
(
int
gross
_i
ncome
)
{
double
contribution
P
ercentage
=
(
gross
I
ncome
>
0
&&
gross
I
ncome
<=
460
)
?
0
:
(
gross
I
ncome
>=
461
&&
gross
I
ncome
<=
1733
)
?
0
.
15
:
(
gross
I
ncome
>=
1734
&&
gross
I
ncome
<=
1891
)
?
0
.
16
:
(
gross
I
ncome
>=
1892
&&
gross
I
ncome
<=
2049
)
?
0
.
17
:
(
gross
I
ncome
>=
2050
)
?
0
.
18
:
0
;
double
contribution
_p
ercentage
=
(
gross
_i
ncome
>
0
&&
gross
_i
ncome
<=
460
)
?
0
:
(
gross
_i
ncome
>=
461
&&
gross
_i
ncome
<=
1733
)
?
0
.
15
:
(
gross
_i
ncome
>=
1734
&&
gross
_i
ncome
<=
1891
)
?
0
.
16
:
(
gross
_i
ncome
>=
1892
&&
gross
_i
ncome
<=
2049
)
?
0
.
17
:
(
gross
_i
ncome
>=
2050
)
?
0
.
18
:
0
;
return
gross
I
ncome
>=
5370
?
5370
*
contribution
P
ercentage
:
gross
I
ncome
*
contribution
P
ercentage
;
return
gross
_i
ncome
>=
5370
?
5370
*
contribution
_p
ercentage
:
gross
_i
ncome
*
contribution
_p
ercentage
;
}
double
calculateIncomeTax
(
double
calculationBasis
)
//-----------------------------------------------------------------------------
///
/// This function calculates the users income tax.
///
/// @param calculationBasis Gross Income - Social Security contribution.
///
/// @return double Users Income Tax
///
//-----------------------------------------------------------------------------
double
calculateIncomeTax
(
double
calculation_basis
)
{
double
incomeTax
=
0
,
localCalculationBasis
=
calculationBasis
;
double
income_tax
=
0
;
double
local_calculation_basis
=
calculation_basis
;
if
(
localCalculationBasis
>=
1000
){
incomeTax
+=
1000
*
0
;
}
else
if
(
localCalculationBasis
>
0
){
incomeTax
+=
localCalculationBasis
*
0
;
if
(
local_calculation_basis
>=
1000
)
{
income_tax
+=
1000
*
0
;
}
else
if
(
local_calculation_basis
>
0
)
{
income_tax
+=
local_calculation_basis
*
0
;
}
local
C
alculation
B
asis
-=
1000
;
local
_c
alculation
_b
asis
-=
1000
;
if
(
localCalculationBasis
>=
500
){
incomeTax
+=
500
*
0
.
2
;
}
else
if
(
localCalculationBasis
>
0
){
incomeTax
+=
localCalculationBasis
*
0
.
2
;
if
(
local_calculation_basis
>=
500
)
{
income_tax
+=
500
*
0
.
2
;
}
else
if
(
local_calculation_basis
>
0
)
{
income_tax
+=
local_calculation_basis
*
0
.
2
;
}
local
C
alculation
B
asis
-=
500
;
local
_c
alculation
_b
asis
-=
500
;
if
(
localCalculationBasis
>=
1000
){
incomeTax
+=
1000
*
0
.
3
;
}
else
if
(
localCalculationBasis
>
0
){
incomeTax
+=
localCalculationBasis
*
0
.
3
;
if
(
local_calculation_basis
>=
1000
)
{
income_tax
+=
1000
*
0
.
3
;
}
else
if
(
local_calculation_basis
>
0
)
{
income_tax
+=
local_calculation_basis
*
0
.
3
;
}
local
C
alculation
B
asis
-=
1000
;
local
_c
alculation
_b
asis
-=
1000
;
if
(
localCalculationBasis
>=
2500
){
incomeTax
+=
2500
*
0
.
4
;
}
else
if
(
localCalculationBasis
>
0
){
incomeTax
+=
localCalculationBasis
*
0
.
4
;
if
(
local_calculation_basis
>=
2500
)
{
income_tax
+=
2500
*
0
.
4
;
}
localCalculationBasis
-=
2500
;
else
if
(
local_calculation_basis
>
0
)
{
income_tax
+=
local_calculation_basis
*
0
.
4
;
}
local_calculation_basis
-=
2500
;
if
(
localCalculationBasis
>
0
){
incomeTax
+=
localCalculationBasis
*
0
.
5
;
if
(
local_calculation_basis
>
0
)
{
income_tax
+=
local_calculation_basis
*
0
.
5
;
}
return
income
T
ax
;
return
income
_t
ax
;
}
//-----------------------------------------------------------------------------
///
/// Asks user if they have children. If user gives unwanted answer, prompts again.
///
/// @return bool true or false depending on if user has children or not.
///
//-----------------------------------------------------------------------------
bool
promptForChildren
()
{
char
answer
;
...
...
@@ -93,21 +158,24 @@ bool promptForChildren ()
int
main
()
{
int
grossIncome
=
askForIncome
();
double
socialSecurityContribution
=
calculateSocialSecurityContribution
(
grossIncome
);
double
incomeTax
=
calculateIncomeTax
(
grossIncome
-
socialSecurityContribution
);
bool
hasChildren
=
promptForChildren
();
if
(
incomeTax
>=
100
&&
hasChildren
){
incomeTax
-=
100
;
}
else
if
(
incomeTax
<=
100
&&
hasChildren
){
incomeTax
=
0
;
}
double
netIncome
=
grossIncome
-
socialSecurityContribution
-
incomeTax
;
printf
(
"Brutto:
\t\t
%12.2f
\n
"
,
(
double
)
grossIncome
);
printf
(
"SV:
\t\t
%12.2f
\n
"
,
-
socialSecurityContribution
);
printf
(
"LSt:
\t\t
%12.2f
\n
"
,
-
incomeTax
);
printf
(
"Netto:
\t\t
%12.2f
\n
"
,
netIncome
);
int
gross_income
=
askForIncome
();
double
social_security_contribution
=
calculateSocialSecurityContribution
(
gross_income
);
double
income_tax
=
calculateIncomeTax
(
gross_income
-
social_security_contribution
);
bool
has_children
=
promptForChildren
();
if
(
income_tax
>=
100
&&
has_children
)
{
income_tax
-=
100
;
}
else
if
(
income_tax
<=
100
&&
has_children
)
{
income_tax
=
0
;
}
double
net_income
=
gross_income
-
social_security_contribution
-
income_tax
;
printf
(
"Brutto:
\t\t
%12.2f
\n
"
,
(
double
)
gross_income
);
printf
(
"SV:
\t\t
%12.2f
\n
"
,
-
social_security_contribution
);
printf
(
"LSt:
\t\t
%12.2f
\n
"
,
-
income_tax
);
printf
(
"Netto:
\t\t
%12.2f
\n
"
,
net_income
);
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment