3-day novice, How do I calculate age in days? [C++]
From: wwwolf (myname_at_alltel.net)
Date: 03/25/05
- Next message: Vince Morgan: "Re: Is It UB ??"
- Previous message: ranjeet: "Is It UB ??"
- Next in thread: Alf P. Steinbach: "Re: 3-day novice, How do I calculate age in days? [C++]"
- Reply: Alf P. Steinbach: "Re: 3-day novice, How do I calculate age in days? [C++]"
- Reply: Karl Heinz Buchegger: "Re: 3-day novice, How do I calculate age in days? [C++]"
- Reply: Francis Glassborow: "Re: 3-day novice, How do I calculate age in days? [C++]"
- Reply: wwwolf: "Re: 3-day novice, How do I calculate age in days? [C++]"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 25 Mar 2005 00:29:18 -0500
This is the 3rd day into teaching myself C++. I have looked at some WWWtutorials, LOTS of
broken links, read the 3 FAQs recommended, and have some books ordered. (although I
ordered a Schildt book before reading the FAQ...Doh! Luckily it is used so it was
cheap.)
My niece is visiting next week and I want to write a small program that will carry on a
short conversation and perform a mathematical demonstration (age in days) to spark her
interest in computer programming.
For me, having the screen cleared, and having the program "cout" what she "cin"ed are
bells and wistles enough, but to have the program appear more interesting, I wanted it
to:
1. Ask her birthdate;
2. Call the OS for the current date;
3. Subtract (date2 - date1);
4. Tell her she is x days old.
In the C-FAQ, which is still over my head, Q13.14 "How can I find the difference between
two dates?" says I should use mktime, difftime, and getdate. I have no idea how to set
these up and I am also weary of following the advice in that FAQ if there is a C++ way
to do it instead.
In the C++FAQ-Lite, also intimidating, Q13.9 "Overloading operators" says I should
provide arithmetic operators to allow (date1 - date2) and provide a reasonable class
type to represent the duration. I think this is the approach I would prefer but I don't
really know how to set this up as well.
If someone could help me I would really appreciate it. Please remember that I am only 3
days old concerning C++ and know squat about C. If you see any bad habits in my code
please tell me. I'm afraid that teaching myself is going to open up the opportunity for
bad habits so I want them corrected now before they really become a habit.
Thanx very much for your help.
// Proggy the conversing program
#include <iostream>
using std::cout;
using std::cin;
int main ()
{
int n (100); // Since I can't figure out how to clear the screen on start, this works.
while (n>0)
{
cout << '\n';
--n;
}
char name [50];
char animal [50];
cout << "What is your name? ";
cin.getline (name,50);
cout << "\nHello " << name << ". My name is Proggy. It is a pleasure to meet you.\n";
cout << "\nWhat is your favorite animal? ";
cin.getline (animal,50);
cout << "\nWell " << name << "!" << " We have something in common, because I like ";
cout << animal << " too!\n\n";
return 0;
}
- Next message: Vince Morgan: "Re: Is It UB ??"
- Previous message: ranjeet: "Is It UB ??"
- Next in thread: Alf P. Steinbach: "Re: 3-day novice, How do I calculate age in days? [C++]"
- Reply: Alf P. Steinbach: "Re: 3-day novice, How do I calculate age in days? [C++]"
- Reply: Karl Heinz Buchegger: "Re: 3-day novice, How do I calculate age in days? [C++]"
- Reply: Francis Glassborow: "Re: 3-day novice, How do I calculate age in days? [C++]"
- Reply: wwwolf: "Re: 3-day novice, How do I calculate age in days? [C++]"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|