Stranica: 1/2.
moja nova aplikacija za linux :D
Postano: 15 srp 2013, 13:58
Postao/la paupav
U biti ona izračunava kolko dani, mjeseci, godina živiš
DOWNLOAD LINK
evo vam kod ako vam nešto ne radi
Kod: Označi sve
#include <iostream>
#include <string>
#include <ctime>
using namespace std;
struct numbers
{
short int day;
short int month;
short int year;
} today, birth, difference;
void lifetimepassed (int, int, int);
int tutToday ();
int tutBirth ();
int error ();
int calculation ();
int clockclock ();
int correcting();
int main()
{
//######################################
clockclock();
cout << "\nSo it is: " << today.day << "." << today.month << "." << today.year << " -formatted in DD.MM.YYYY";
cout << "\nIs that date correct? Wtite 'no' to enter date manually. ";
string correct;
correct = "Yes";
getline (cin,correct);
if (correct == "no")
{
cout << "\nPlease re-enter it ";
tutToday();
}
else
{
cout << "\nSystem date active. ";
}
tutBirth();
cout << "\nSo you were born: " << birth.day << "." << birth.month << "." << birth.year << " -formatted in DD.MM.YYYY";
error ();
calculation ();
lifetimepassed (difference.day, difference.month, difference.year);
//##################################
}
int tutToday()
{
cout << "\nEnter today's day: ";
cin >> today.day;
cout << "Enter today's month: ";
cin >> today.month;
cout << "Enter today's year: ";
cin >> today.year;
return 0;
}
int tutBirth ()
{
cout << "\nEnter your birth day (just number): ";
cin >> birth.day;
cout << "Enter your birth month (just number): ";
cin >> birth.month;
cout << "Enter your birth year (just number): ";
cin >> birth.year;
return 0;
}
int error()
{
while (today.day > 31 || today.month > 12 )
{
cout << "\nThere is some problem with today's date, please re-enter it" << endl;
tutToday();
}
while (birth.day > 31 || birth.month > 12 )
{
cout << "\nThere is some problem with your birth date, please re-enter it" << endl;
tutBirth ();
}
return 0;
}
int calculation ()
{
difference.year = today.year - birth.year ;
//Month conversion
if (today.month < birth.month)
{
difference.year--;
today.month += 12;
}
difference.month = today.month - birth.month ;
if (today.day < birth.day)
{
difference.month--;
today.day += 30;
}
difference.day = today.day - birth.day ;
return 0;
}
int clockclock()
{
time_t t = time(NULL);
tm* timePtr = localtime(&t);
today.day = timePtr->tm_mday;
today.month = timePtr->tm_mon += 1;
today.year = timePtr->tm_year +=1900;
return 0;
}
void lifetimepassed (int a, int b, int c)
{
cout << "\nYou have lived: \n" << difference.day << " days\n" << difference.month << " months\n" << difference.year << "years\n\n";
}
ako neznate kako otvorit *.out datoteku pokazano vam je u slici u privitku

Re: moja nova aplikacija za linux :D
Postano: 15 srp 2013, 16:37
Postao/la shrike
Baš se neće iskompajlirat. Daje grešku:
Kod: Označi sve
kolkozivis.cpp:52:91: warning: missing terminating '"' character [-Winvalid-pp-token]
cout << "\nSo you were born: " << birth.day << "." << birth.month << "." << birth.year << " -formatted in
^
kolkozivis.cpp:52:91: error: expected expression
kolkozivis.cpp:53:11: warning: missing terminating '"' character [-Winvalid-pp-token]
DD.MM.YYYY";
^
2 warnings and 1 error generated.
Re: moja nova aplikacija za linux :D
Postano: 15 srp 2013, 17:12
Postao/la blacx
Meni radi kompajl.

Jesi dobro kopirao, očito ti fali završni navodnik?
You have lived:
22 days
9 months
24years
Re: moja nova aplikacija za linux :D
Postano: 15 srp 2013, 18:33
Postao/la paupav
shrike je napisao/la:Baš se neće iskompajlirat. Daje grešku:
Kod: Označi sve
kolkozivis.cpp:52:91: warning: missing terminating '"' character [-Winvalid-pp-token]
cout << "\nSo you were born: " << birth.day << "." << birth.month << "." << birth.year << " -formatted in
^
kolkozivis.cpp:52:91: error: expected expression
kolkozivis.cpp:53:11: warning: missing terminating '"' character [-Winvalid-pp-token]
DD.MM.YYYY";
^
2 warnings and 1 error generated.
čudno. vjerojatno je ovo od osobe iznad mene
You have lived:
26 days
9 months
15years
Re: moja nova aplikacija za linux :D
Postano: 15 srp 2013, 19:01
Postao/la Medojedni jazavac
Daj napravi da mozes birat format outputa. Tipa, samo sekunde, minute, dani, mjeseci, godine. Pa kombinacije i sl.
Re: moja nova aplikacija za linux :D
Postano: 15 srp 2013, 19:34
Postao/la 4ndY
Meni isto radi^TM
Medojedni jazavac je napisao/la:Daj napravi da mozes birat format outputa. Tipa, samo sekunde, minute, dani, mjeseci, godine. Pa kombinacije i sl.
Mislim da bi bilo zgodnije i kraće da se sve računa u sistemskom vremenu, a onda se tek na kraju preračuna u željeni format (
hint).
Re: moja nova aplikacija za linux :D
Postano: 15 srp 2013, 20:36
Postao/la paupav
Medojedni jazavac je napisao/la:Daj napravi da mozes birat format outputa. Tipa, samo sekunde, minute, dani, mjeseci, godine. Pa kombinacije i sl.
Može ovako?
Kod: Označi sve
#include <iostream>
#include <string>
#include <ctime>
using namespace std;
struct numbers
{
short int day;
short int month;
short int year;
} today, birth, difference;
void lifetimepassed (int, int, int);
int tutToday ();
int tutBirth ();
int error ();
int calculation ();
int clockclock ();
int correcting();
int recalculation ();
int main()
{
//######################################
clockclock();
cout << "\nSo it is: " << today.day << "." << today.month << "." << today.year << " -formatted in DD.MM.YYYY";
cout << "\nIs that date correct? Wtite 'no' to enter date manually. ";
string correct;
correct = "Yes";
getline (cin,correct);
if (correct == "no")
{
cout << "\nPlease re-enter it ";
tutToday();
}
else
{
cout << "\nSystem date active. ";
}
tutBirth();
cout << "\nSo you were born: " << birth.day << "." << birth.month << "." << birth.year << " -formatted in DD.MM.YYYY";
error ();
calculation ();
lifetimepassed (difference.day, difference.month, difference.year);
recalculation ();
//##################################
}
int tutToday()
{
cout << "\nEnter today's day: ";
cin >> today.day;
cout << "Enter today's month: ";
cin >> today.month;
cout << "Enter today's year: ";
cin >> today.year;
return 0;
}
int tutBirth ()
{
cout << "\nEnter your birth day (just number): ";
cin >> birth.day;
cout << "Enter your birth month (just number): ";
cin >> birth.month;
cout << "Enter your birth year (just number): ";
cin >> birth.year;
return 0;
}
int error()
{
while (today.day > 31 || today.month > 12 )
{
cout << "\nThere is some problem with today's date, please re-enter it" << endl;
tutToday();
}
while (birth.day > 31 || birth.month > 12 )
{
cout << "\nThere is some problem with your birth date, please re-enter it" << endl;
tutBirth ();
}
return 0;
}
int calculation ()
{
difference.year = today.year - birth.year ;
//Month conversion
if (today.month < birth.month)
{
difference.year--;
today.month += 12;
}
difference.month = today.month - birth.month ;
if (today.day < birth.day)
{
difference.month--;
today.day += 30;
}
difference.day = today.day - birth.day ;
return 0;
}
int clockclock()
{
time_t t = time(NULL);
tm* timePtr = localtime(&t);
today.day = timePtr->tm_mday;
today.month = timePtr->tm_mon += 1;
today.year = timePtr->tm_year +=1900;
return 0;
}
int recalculation ()
{
int recalcMonth, recalcDay, recalcHou, recalcMin, recalcSec ;
recalcMonth = (difference.year * 12)+ difference.month ;
recalcDay = (recalcMonth * 30) + difference.day;
recalcHou = recalcDay * 24;
recalcMin = recalcHou * 60;
recalcSec = recalcMin * 60;
cout << "\nWhich is \n= " << recalcMonth << " months\n= " << recalcDay << " days\n= " << recalcHou << " hours\n= " << recalcMin << " minutes\n= " << recalcSec << " seconds\n";
return 0;
}
void lifetimepassed (int a, int b, int c)
{
cout << "\nYou have lived: \n" << difference.day << " days\n" << difference.month << " months\n" << difference.year << "years\n\n";
}
DOWNLOAD LINK
Re: moja nova aplikacija za linux :D
Postano: 15 srp 2013, 20:44
Postao/la Cooleech
You have lived:
11 days
5 months
35years
Which is
= 425 months
= 12761 days
= 306264 hours
= 18375840 minutes
= 1102550400 seconds
Cool
eech, samo nedostaje razmak kod broja godina

Re: moja nova aplikacija za linux :D
Postano: 15 srp 2013, 21:27
Postao/la paupav
Cooleech je napisao/la:You have lived:
11 days
5 months
35years
Which is
= 425 months
= 12761 days
= 306264 hours
= 18375840 minutes
= 1102550400 seconds
Cool
eech, samo nedostaje razmak kod broja godina

hahah evo evo
Kod: Označi sve
#include <iostream>
#include <string>
#include <ctime>
using namespace std;
struct numbers
{
short int day;
short int month;
short int year;
} today, birth, difference;
void lifetimepassed (int, int, int);
int tutToday ();
int tutBirth ();
int error ();
int calculation ();
int clockclock ();
int correcting();
int recalculation ();
int main()
{
//######################################
clockclock();
cout << "\nSo it is: " << today.day << "." << today.month << "." << today.year << " -formatted in DD.MM.YYYY";
cout << "\nIs that date correct? Wtite 'no' to enter date manually. ";
string correct;
correct = "Yes";
getline (cin,correct);
if (correct == "no")
{
cout << "\nPlease re-enter it ";
tutToday();
}
else
{
cout << "\nSystem date active. ";
}
tutBirth();
cout << "\nSo you were born: " << birth.day << "." << birth.month << "." << birth.year << " -formatted in DD.MM.YYYY";
error ();
calculation ();
lifetimepassed (difference.day, difference.month, difference.year);
recalculation ();
//##################################
}
int tutToday()
{
cout << "\nEnter today's day: ";
cin >> today.day;
cout << "Enter today's month: ";
cin >> today.month;
cout << "Enter today's year: ";
cin >> today.year;
return 0;
}
int tutBirth ()
{
cout << "\nEnter your birth day (just number): ";
cin >> birth.day;
cout << "Enter your birth month (just number): ";
cin >> birth.month;
cout << "Enter your birth year (just number): ";
cin >> birth.year;
return 0;
}
int error()
{
while (today.day > 31 || today.month > 12 )
{
cout << "\nThere is some problem with today's date, please re-enter it" << endl;
tutToday();
}
while (birth.day > 31 || birth.month > 12 )
{
cout << "\nThere is some problem with your birth date, please re-enter it" << endl;
tutBirth ();
}
return 0;
}
int calculation ()
{
difference.year = today.year - birth.year ;
//Month conversion
if (today.month < birth.month)
{
difference.year--;
today.month += 12;
}
difference.month = today.month - birth.month ;
if (today.day < birth.day)
{
difference.month--;
today.day += 30;
}
difference.day = today.day - birth.day ;
return 0;
}
int clockclock()
{
time_t t = time(NULL);
tm* timePtr = localtime(&t);
today.day = timePtr->tm_mday;
today.month = timePtr->tm_mon += 1;
today.year = timePtr->tm_year +=1900;
return 0;
}
int recalculation ()
{
int recalcMonth, recalcDay, recalcHou, recalcMin, recalcSec ;
recalcMonth = (difference.year * 12)+ difference.month ;
recalcDay = (recalcMonth * 30) + difference.day;
recalcHou = recalcDay * 24;
recalcMin = recalcHou * 60;
recalcSec = recalcMin * 60;
cout << "\nWhich is \n= " << recalcMonth << " months\n= " << recalcDay << " days\n= " << recalcHou << " hours\n= " << recalcMin << " minutes\n= " << recalcSec << " seconds\n";
return 0;
}
void lifetimepassed (int a, int b, int c)
{
cout << "\nYou have lived: \n" << difference.day << " days\n" << difference.month << " months\n" << difference.year << " years\n\n";
}
P.S mjeseci nisu 100% točni, jer nije u decimalnom zapisu
Re: moja nova aplikacija za linux :D
Postano: 15 srp 2013, 23:50
Postao/la 4ndY
Što ako je prijestupna godina ili ako si rođen u prijestupnoj? Falit će jedan dan zar ne? Slično je i sa brojem dana u mjesecu...