Why the programms doesn't works?
Jul 5, 2019 at 9:43pm UTC
I made little zodiak's signs finder(?) and it seens to be working but does nothing in command line. i used russian to get output, the strange symbols are zodiak signs starting from capricorn. Output is in the switch()
Where the mistake can be?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
int main (void )
{
setlocale (LC_ALL, "Russian" );
ofstream datein ("dates.txt" );
datein << "15/10/1960" << endl;
datein << "21/08/1974" << endl;
datein << "26/02/1992" << endl;
datein << "18/10/1993" << endl;
datein << "10/07/2017" ;
datein.close();
ifstream dateout ("dates.txt" );
string strm;
getline (dateout, strm);
ofstream dateday ("days.txt" );
string strv;
while (!dateout.eof()) //days date file "writer"?
{
for (int i=0; i<2; i++)
{
strv[i]=strm[i];
}
dateday << strv << endl;
}
dateday.close();
ofstream datemonth ("months.txt" );
while (!dateout.eof()) //month date file "writer"?
{
for (int i=0+3; i<2+3; i++)
{
strv[i-3]=strm[i];
}
datemonth << strv << endl;
}
datemonth.close();
dateout.close();
ifstream datedayr ("days.txt" );
ifstream datemonthr ("months.txt" );
for (int i=0; i<5; i++)
{
string sd;
string sm;
getline (datemonthr, sm);
getline (datedayr, sd);
int days = atoi(sd.c_str());
int mont = atoi (sm.c_str());
switch (mont)
{
case 1:
if (days <= 19)
cout << "Êîçåðîã" << endl;
else if (days >= 20)
cout << "Âîäîëåé" << endl;
break ;
case 2:
if (days <= 18)
cout << "Âîäîëåé" << endl;
else if (days >= 19)
cout << "Ðûáû" << endl;
break ;
case 3:
if (days <= 20)
cout << "Ðûáû" << endl;
else if (days >= 21)
cout << "Îâåí" << endl;
break ;
case 4:
if (days <= 19)
cout << "Îâåí" << endl;
else if (days >= 20)
cout << "Òåëåö" << endl;
break ;
case 5:
if (days <= 20)
cout << "Òåëåö" << endl;
else if (days >= 21)
cout << "Áëèçíåöû" << endl;
break ;
case 6:
if (days <= 20)
cout << "Áëèçíåöû" << endl;
else if (days >= 21)
cout << "Ðàê" << endl;
break ;
case 7:
if (days <= 22)
cout << "Ðàê" << endl;
else if (days >= 23)
cout << "Ëåâ" << endl;
break ;
case 8:
if (days <= 22)
cout << "Ëåâ" << endl;
else if (days >= 23)
cout << "Äåâà" << endl;
break ;
case 9:
if (days <= 22)
cout << "Äåâà" << endl;
else if (days >= 23)
cout << "Âåñû" << endl;
break ;
case 10:
if (days <= 22)
cout << "Âåñû" << endl;
else if (days >= 23)
cout << "Ñêîðïèîí" << endl;
break ;
case 11:
if (days <= 21)
cout << "Ñêîðïèîí" << endl;
else if (days >= 22)
cout << "Ñòðåëåö" << endl;
break ;
case 12:
if (days <= 21)
cout << "Ñòðåëåö" << endl;
else if (days >= 22)
cout << "Êîçåðîã" << endl;
break ;
default :
cout << "ERROR" << endl;
break ;
}
}
datedayr.close();
datemonthr.close();
}
Last edited on Jul 5, 2019 at 9:43pm UTC
Jul 6, 2019 at 10:20pm UTC
There's a much easier way to parse out the day and month from the file. Just use getline:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
int
main(void )
{
setlocale(LC_ALL, "Russian" );
ofstream dateout("dates.txt" );
dateout << "15/10/1960" << endl;
dateout << "21/08/1974" << endl;
dateout << "26/02/1992" << endl;
dateout << "18/10/1993" << endl;
dateout << "10/07/2017" ;
dateout.close();
ifstream datein("dates.txt" );
string monthString, dayString, scratch;
while (getline(datein, dayString, '/' )) { // read until '/'
getline(datein, monthString, '/' );
getline(datein, scratch); // skip to end of line.
int days = stoi(dayString);
int mont = stoi(monthString);
switch (mont) {
case 1:
if (days <= 19)
cout << "Êîçåðîã" << endl;
else if (days >= 20)
cout << "Âîäîëåé" << endl;
break ;
case 2:
if (days <= 18)
cout << "Âîäîëåé" << endl;
else if (days >= 19)
cout << "Ðûáû" << endl;
break ;
case 3:
if (days <= 20)
cout << "Ðûáû" << endl;
else if (days >= 21)
cout << "Îâåí" << endl;
break ;
case 4:
if (days <= 19)
cout << "Îâåí" << endl;
else if (days >= 20)
cout << "Òåëåö" << endl;
break ;
case 5:
if (days <= 20)
cout << "Òåëåö" << endl;
else if (days >= 21)
cout << "Áëèçíåöû" << endl;
break ;
case 6:
if (days <= 20)
cout << "Áëèçíåöû" << endl;
else if (days >= 21)
cout << "Ðàê" << endl;
break ;
case 7:
if (days <= 22)
cout << "Ðàê" << endl;
else if (days >= 23)
cout << "Ëåâ" << endl;
break ;
case 8:
if (days <= 22)
cout << "Ëåâ" << endl;
else if (days >= 23)
cout << "Äåâà" << endl;
break ;
case 9:
if (days <= 22)
cout << "Äåâà" << endl;
else if (days >= 23)
cout << "Âåñû" << endl;
break ;
case 10:
if (days <= 22)
cout << "Âåñû" << endl;
else if (days >= 23)
cout << "Ñêîðïèîí" << endl;
break ;
case 11:
if (days <= 21)
cout << "Ñêîðïèîí" << endl;
else if (days >= 22)
cout << "Ñòðåëåö" << endl;
break ;
case 12:
if (days <= 21)
cout << "Ñòðåëåö" << endl;
else if (days >= 22)
cout << "Êîçåðîã" << endl;
break ;
default :
cout << "ERROR" << endl;
break ;
}
}
}
Topic archived. No new replies allowed.