Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
otsall
/
iax0583
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
c106c10f
authored
Nov 05, 2018
by
otsall
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
23ddfa6f
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
112 additions
and
0 deletions
Lab10/task.c
Lab10/task.c
0 → 100644
View file @
c106c10f
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#define USERS 6
#define DATAVAR 4
#define MAXLENGTH 20
#define MAXYEARS 10
void
fillarray
(
char
array
[
USERS
][
DATAVAR
][
MAXLENGTH
]);
int
checklogin
(
char
user
[],
char
pass
[],
char
array
[
USERS
][
DATAVAR
][
MAXLENGTH
]);
void
futurebalance
(
char
array
[
USERS
][
DATAVAR
][
MAXLENGTH
],
int
years
,
int
user
);
int
main
(){
char
array
[
USERS
][
DATAVAR
][
MAXLENGTH
],
username
[
MAXLENGTH
],
password
[
MAXLENGTH
];
int
i
=
-
1
,
years
;
fillarray
(
array
);
while
(
i
==
-
1
){
puts
(
"input username and password"
);
scanf
(
"%s"
,
username
);
scanf
(
"%s"
,
password
);
i
=
checklogin
(
username
,
password
,
array
);
}
puts
(
"how many years to calculate future balance?"
);
scanf
(
"%d"
,
&
years
);
while
(
years
>
MAXYEARS
){
printf
(
"cant calculate more than %d years
\n
"
,
MAXYEARS
);
scanf
(
"%d"
,
&
years
);
}
printf
(
"calculating balance for %d years
\n
"
,
years
);
futurebalance
(
array
,
years
,
i
);
return
0
;
}
void
fillarray
(
char
array
[
USERS
][
DATAVAR
][
MAXLENGTH
]){
int
i
,
j
;
for
(
i
=
0
;
i
<
USERS
;
i
++
){
for
(
j
=
0
;
j
<
DATAVAR
;
j
++
){
scanf
(
"%s"
,
array
[
i
][
j
]);
}
}
/*for(i = 0; i < USERS; i++){
for(j = 0; j < DATAVAR; j++){
if(j == 0){
printf("\nfor user %s :", array[i][j]);
}else{
printf(" %s", array[i][j]);
}
}
}*/
return
;
}
int
checklogin
(
char
user
[],
char
pass
[],
char
array
[
USERS
][
DATAVAR
][
MAXLENGTH
]){
int
i
,
j
;
for
(
i
=
0
;
i
<
USERS
;
i
++
){
if
(
strcmp
(
user
,
array
[
i
][
0
])
==
0
){
if
(
strcmp
(
pass
,
array
[
i
][
1
])
==
0
){
j
=
1
;
break
;
}
else
{
puts
(
"password aint right"
);
break
;
}
}
else
{
continue
;
}
}
if
(
i
==
USERS
){
puts
(
"username aint right"
);
return
-
1
;
}
if
(
j
==
1
){
printf
(
"hello, %s
\n
"
,
array
[
i
][
0
]);
return
i
;
}
else
{
return
-
1
;
}
}
void
futurebalance
(
char
array
[
USERS
][
DATAVAR
][
MAXLENGTH
],
int
years
,
int
user
){
float
currentbal
,
balance
[
years
];
int
i
=
0
,
j
;
if
(
strncmp
(
"gold"
,
array
[
user
][
2
],
1
)
==
0
){
puts
(
"account is of gold status"
);
i
=
1
;
}
else
{
puts
(
"account is of silver status"
);
}
printf
(
"your balance right now is %s
\n
"
,
array
[
user
][
3
]);
currentbal
=
atof
(
array
[
user
][
3
]);
if
(
i
==
1
){
for
(
j
=
0
;
j
<
years
;
j
++
){
currentbal
=
1
.
006
*
1
.
006
*
currentbal
;
balance
[
j
]
=
currentbal
;
printf
(
"%d year(s) from now your balance will be %.2f
\n
"
,
j
+
1
,
balance
[
j
]);
}
}
else
{
for
(
j
=
0
;
j
<
years
;
j
++
){
currentbal
=
1
.
005
*
currentbal
;
balance
[
j
]
=
currentbal
;
printf
(
"%d year(s) from now your balance will be %.2f
\n
"
,
j
+
1
,
balance
[
j
]);
}
}
return
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment