ok, so i have to write a program that takes in the current date and the date of the expiration of a food product in the form of mm/dd/yyyy
then i have to make 3 bool functions that do no input from the keyboard nor output to the screen. they do only logic.
those three bool functions are 'isvalid' which is true if the date is a valid date and false if otherwise. the other bool function is 'thesame' which is true if the two dates are the same and false otherwise. and the last bool function is called 'earlier' which is true if the 1st date (the expiration date) is earlier than the 2nd date (the current date)
i already made the functions, but then at the end of the program, i have to have the program either say 'the dates are the same', 'expiration date/current date is not valid', 'the expiration date is earlier than today', or 'the expiration date is later than today'
but i have no idea how to make my program put those outputs out. i have to use 'if' statements, please help!
Help with C++ programming on visual studio 2005?
If you're doing all this, then surely you know basic input and output...use cout %26lt;%26lt; "blah blah" %26lt;%26lt; endl; or output %26lt;%26lt; "blah blah" %26lt;%26lt; endl; where output is an ofstream object that points to a text file.
Um, I'm talking about basic input and output, probably the first and second things they teach you:
string name;
cout %26lt;%26lt; "enter you name:" %26lt;%26lt; endl;
cin %26gt;%26gt; name;
cout %26lt;%26lt; "nice to meet you, " %26lt;%26lt; name %26lt;%26lt; endl;
If you can't use ofstream then just use cout...pretty simple.
You're making this too complicated:
if(isvalid(date))
cout %26lt;%26lt; "valid" %26lt;%26lt; endl;
... etc.
Reply:EDIT:
Explain what EXACTLY have you taken in your course to be included in a solution! What's not mentioned means to be excluded by default (as arrays if you don't mention them)
Example:
Datatypes: .....
Selection: if, case
OOP: Classes, Inheritance ...etc.
From your previous post, we're done explaining how to extract the data from the input;
remember my last post, you get a vector of tokens;
index 0 contains the month
index 1 contains the day and
index 2 contains the year
when you compare, you compare first the year, if the year is less, then the date is earlier, else you compare the month if the year is the same, if the month is the same, you finally go to compare with the day; the logic is simple.
I can see that you are beginning and using vectors wouldn't do you good if you are not familiar with arrays.
Again ...
Same .. you compare a string to string and no need to check the tokens
if they are not the same, then you begin tokenizing in such you start comparing with yyyy then mm then dd.
Draw your logic in a Flowchart, that's how I started programming from my lecturers to concentrate more on the logic rather than memorizing code.
Google for "C++ Tutorial" and look there for "selection" and conditions for how to use if statements.
Good luck
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment