I'm trying to make a program that opens a file and calculates the days elapsed from the date.
The dates are in the file as follows: 30-10-2018
. But I'm having trouble with the output that is printing garbage.
Follow my code so far.
include iostream
include fstream
include sstream
include string
include vector
using namespace std;
int main() {
std::vector<std::string> my_arr;
std::ifstream dict_file("bissextos.txt");
std::string line;
while(std::getline(dict_file, line))
{
std::string new_line;
new_line = line + "\n";
std::cout<<new_line;
my_arr.push_back(new_line);
std::istringstream stm(new_line) ;
int day, month, year ;
char delim ;
stm >> day >> delim ;
stm >> month >> delim ;
stm >> year ;
int meses[] = {31,28,31,30,31,30,31,31,30,31,30,31};
int meses_bis[] = {31,29,31,30,31,30,31,31,30,31,30,31};
int soma_meses, contagem_dias, ano_bis;
if (year % 4 == 0 && (year % 400 == 0 || year % 100 != 0)) {
ano_bis = 'S';
}
else {
ano_bis = 'N';
}
switch(ano_bis) {
case 'S' :
for (int i=0; i<(month -1); i++){
soma_meses += meses_bis[i];
contagem_dias = soma_meses + day;
}
cout << "int: " << contagem_dias;
break;
default :
for (int i=0; i<(month -1); i++){
soma_meses += meses[i];
contagem_dias = soma_meses + day;
}
cout << "int: " << contagem_dias;
}
}
return 0;
}