0
Speak up your people! I took a question here on the internet to do that nothing comes out at all. He asks the following: Want to make a program that reads the name of the book that will be borrowed, the type of user (teacher or student) and the date of book loan. The program should consider that the teacher has ten days to return the book and the student only five days. Should any of them return with delay, the program should calculate the fine related to this delay considering the amount of R $ 0,50 per delay day. The program should read the actual return date and at the end of the execution, it should print a receipt as shown below:
Name of the book: XXXXX
User type: XXXXX
Date of loan: XX/XX/XXXX
Expected date of return: XX/XX/XXXX
Date of return: XX/XX/XXXX
Late fine: R$ XXX,XX
-Name of the book: -Type of the user: -Date of the loan: -Expected date of return: -Date of return: -Late payment of a fine:
My biggest problem is with the dates, because I can’t operate with them.
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<locale.h>
int main(){
setlocale(LC_ALL, "portuguese");
char usuario[10], livro[30];
int dia, mes, ano;
printf("Insira o nome do livro: ");
scanf("%s", &livro);
printf("Insira o tipo do usuário: ");
scanf("%s", &usuario);
printf("Insira a data do emprestimo: ");
scanf("%d%*c%d*c%d", &dia, &mes, &ano);
if((usuario[0]=='A')&&(usuario[1]=='L')&&(usuario[2]=='U'))
{
Nessa função "if" eu iria colocar um for para contar os dias de
atraso entre data de emprestimo e data da devolução, por exemplo:
dataemp=dataemp+5 //Pois alunos tem 5 dias para devolver
for(i = 0; dataemp<=datadev; i++)
multa = i * 0.50;
}
if((usuario[0]=='P')&&(usuario[0]=='R')&&(usuario[0]=='O'))
{
dataemp=dataemp+10 //Pois professor tem 10 dias para devolver
for(i = 0; dataemp<=datadev; i++)
multa = i * 0.50;
}
}
How can I take the user’s date, subtract these dates, and add days in the user’s date? I’ve read about time. h but I did not understand her well enough to implement my code with her. Ta fuck, seriously, 4 days trying to do this and do not pass the algorithm I wrote above.
In fact, on the lines of the form
dataemp=dataemp+
xxx, you forgot the semicolon at the end; inside the firstif
has a comment without the markers//
or/* */
; and you usually want to compare strings usingstrcmp()
orstrncmp()
, thus:if (!strncmp(usuario, "ALU", 3))
– Wtrmute