Hello, I am having some trouble on a light program. Ive spent the last 5 hours on it, and I'm a beginner so I'm relatively slow. =)
I will show you what I have, but first I'll explain to you what I'm doing.
I am writing a numerology program.
I ask the user to input a date, in the format (DD-MM-YYYY)
After validating that the dates are logical, I must then add the digits together until they form one single digit. For example:
Date: 01-13-1967
0+1+1+3+1+9+6+7=28, then 2+8=10, and finally 1+0=1.
After gaining my condensed number, I plug it into a switch statement to get a quote. Just a fun little code.
Anyways, my problem lies with the crunching of the numbers! I cant figure out how to take a user input and crunch it down.
The closest I came...
I made a few 'char' variables and used a few as dummies to eliminate the dashes in the date.
It was easy the first round with cin user input, but how would I set char values when the program was being run?
Was I even on the right track there? Is there an easier way?
(Haha its a mess I know, just playing around with ideas)
Heres what I tried:
#include <iostream>
using namespace std;
int main ()
{
int m;
int z;
char a;
char b;
char c;
char d;
char e;
char f;
char g;
char h;
char i;
char j;
z=-1;
cout << "Please, enter your birthday: ";
cin >> a >> b >> c >> d >> e >> f >> g >> h >> i >> j;
cout << a << b;
cout << d << e;
cout << g << h << i << j << endl;
system ("PAUSE");
return 0;
}
Here is my complete code so far. I have the date validation DONE but I just need to get the number crunching down.
#include <iostream>
using namespace std;
int main ()
{
int d;
int m;
int y;
int z;
char A;
char B;
cout << "Enter your birthdate (DD-MM-YYYY): ";
cin >> d
cout<< d
z=0;
do
{
if(m==2) //FEBRUARY
{
if ((y%400==0) || (y%100==0) || (y%4==0)) //LEAP YEAR
{
if( (d<1) || (d>29) || (y<1875) || (y>2199) ) //VALIDATION
{
z=z+1;
}
}
else // NO LEAP YEAR
{
if ( (d<1) || (d>28) || (y<1875) || (y>2199) ) //VALIDATION
{
z=z+1;
}
}
}
else // ANY OTHER MONTH BESIDES FEBRUARY
{
if(m<7 ) //JANUARY TO JUNE
{
if(m%2==0) // JANUARY TO JUNE: EVEN MONTHS
{
if( (d<1) || (d>30) || (y<1875) || (y>2199) )
{
z=z+1;
}
}
else // JANUARY TO JUNE: ODD MONTHS
{
if( (d<1) || (d>31) || (y<1875) || (y>2199) )
{
z=z+1;
}
}
}
else //JULY TO DECEMBER
{
if(m%2==0) //JULY TO DECEMBER: EVEN MONTHS
{
if( (d<1) || (d>31) || (y<1875) || (y>2199) )
{
z=z+1;
}
}
else //JULY TO DECEMBER: ODD MONTHS
{
if( (d<1) || (d>30) || (y<1875) || (y>2199) )
{
z=z+1;
}
}
}
}
}while (z > 0);
// NUMBER CRUNCHING GOES HERE!!!!
switch (x)
{
case '0'
cout << x << "Good things, when short, are twice as good." << endl;
break;
case '1'
cout << x << "I have found the best way to give advice to your children is to find out what they want and then advise them to do it." << endl;
break;
case '2'
cout << x << "He only profits from praise who values criticism." << endl;
break;
case '3'
cout << x << "Whatever advice you give, be brief." << endl;
break;
case '4'
cout << x << "He who is too busy doing good finds no time to be good." << endl;
break;
case '5'
cout << x << "Go put your creed into the deed or speak with double tongue." << endl;
break;
case '6'
cout << x << "Write it on your heart that every day is the best day in the year. No man has learned anything rightly, until he knows that every day is Doomsday" << endl;
break;
case '7'
cout << x << "In three words I can sum up everything I've learned about life: it goes on." << endl;
break;
case '8'
cout << x << "If better were within, better would come out." << endl;
break;
case '9'
cout << x << "Never put off until tomorrow what you can do today." << endl;
break;
case '0'
cout << x << "Pride costs us more than hunger, thirst, and cold." << endl;
break;
}
I realize it all need polishing. I'm just stuck at a mental brick wall!
Any help is appreciated. Thank you!