Mar 4, 2012 at 7:42am UTC
I am trying to erase a number before "Magic Date", how do I do that?
how come it doesn't work for "not Magic Date".
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int total, month, day, year;
cout << "Enter month: ";
cin >> month;
cout << "Enter day: ";
cin >> day;
cout << "Enter a two digit year: ";
cin >> year;
cin.ignore(2);
total = month * day;
if (total == year)
{
cout <<year << "magic year!"<<endl;
}
else
{
cout << "\nnot a magic year!"<<endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
thanks!!!
Mar 4, 2012 at 9:44am UTC
you can't erase it (the year
), you can just initialized it to 0 (zero)
Mar 4, 2012 at 7:27pm UTC
sorry for being unclear.
This is my output...
Enter month: 1
Enter date: 12
enter year: 12
12magic date!
press any key...
"12magic date!"
I am expecting "magic date!"
thank you!
Last edited on Mar 4, 2012 at 7:41pm UTC
Mar 4, 2012 at 7:52pm UTC
On the line you output "magic date!", just don't output the year anymore.
Mar 4, 2012 at 7:54pm UTC
because you have cout <<year << "magic year!" <<endl;
, which outputs the year variable first and then the nameless "magic year" string. just take out the year variable in the cout statement.
like this;
cout "magic year!" <<endl;