I have this code:
----------------------------------------Code:#include <iostream> using namespace std; int bday; int bmonth; int byear; int cday; int cmonth; int cyear; char cont; int spd; int main() { do{ bday=0; cday=0; byear=0; cyear=0; cmonth=0; bmonth=0; spd=0; system("cls"); cout<< "SLEEPY TIME!" << endl; cout<< "This is a program that calculates how much you have time you have slept in your entire life. Hit ENTER to continue." << endl; cin.get(); system("cls"); cout<<"How many hours on average do you sleep in a night?" << endl; cin>> spd; system("cls"); cout<<"What year were you born in? (example: 1994)" << endl; cin>> byear; cin.ignore(); system("cls"); cout<<"What month of the year were you born in? Please represent numerically (january: 1 , february: 2 , etc.)" << endl; cin>> bmonth; cin.ignore(); system("cls"); cout<<"What day of the month were you born? (example: 10)" << endl; cin>> bday; cin.ignore(); system("cls"); cout<<"What year is it currently? (example: 1994)" << endl; cin>> cyear; cin.ignore(); system("cls"); cout<<"What month is it currently? Please represent numerically (january: 1 , february: 2 , etc.)" << endl; cin>> cmonth; cin.ignore(); system("cls"); cout<<"What day of the month is it currently? (example: 10) \n"; cin>> cday; cin.ignore(); system("cls"); cout<<"You have been sleeping for: "<< (cyear - byear)*(spd/24) <<" years, " << (cmonth - bmonth)*(spd/24) <<" months, and "<< (cday - bday)*(spd/24) <<" days.\n(Based on 8 hours of sleep a day, days rounded)" << endl; cout<< "0. Quit" <<endl; cout<< "1. Restart" <<endl; cin>> cont; cin.ignore(); } while (cont); }
The problem is that for some reason, when I put in say, 10 for cyear, cday, cmonth, byear, and bmonth, but put in 15 bday, and 1 spd, it comes out with 0 days, 0 years, and 0 months. do you know why?
thanks.



LinkBack URL
About LinkBacks


