Commit c106c10f by otsall

Upload New File

parent 23ddfa6f
Showing with 112 additions and 0 deletions
#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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment