Troubles with my if statements
I keep getting this error (using the bloodshed compiler)
"expected primary-expression before '%26gt;' token"
here is the code ...
#include %26lt;iostream%26gt;
#include %26lt;string%26gt;
using namespace std;
int main()
{
int Month;
int Day;
int Year;
//month
cout%26lt;%26lt; "Please enter the Month (03): ";
cin%26gt;%26gt; Month;
if (Month %26lt; 01 %26amp;%26amp; %26gt; 12);
cout%26lt;%26lt; "Please enter a valid Month in 2 digit format\n";
//day
cout%26lt;%26lt; "Please enter the Day (15): ";
cin%26gt;%26gt; Day;
if (Day %26lt; 01 %26amp;%26amp; %26gt; 31);
cout%26lt;%26lt; "Please enter a valid Day in 2 digit format\n";
//year
cout%26lt;%26lt; "Please enter the Year (2000): ";
cin%26gt;%26gt; Year;
if (Month %26lt; 1800 %26amp;%26amp; %26gt; 2999);
cout%26lt;%26lt; "Please enter a valid Year in 4 digit format\n";
cout%26lt;%26lt; "The date you entered is " %26lt;%26lt;Month%26lt;%26lt;"/"%26lt;%26lt;Day%26lt;%26lt;"/"%26lt;%26lt;Year%26lt;%26lt;"\n";
return 0;
}
C++ programing?
Instead of:
if (Month %26lt; 01 %26amp;%26amp; %26gt; 12);
cout%26lt;%26lt; "Please enter a valid Month in 2 digit format\n";
You should write:
if (Month %26lt; 1 || Month %26gt; 12) {
cout%26lt;%26lt; "Please enter a valid Month in 2 digit format\n";
}
1) Don't put a semicolon after the closing ).
2) Don't prefix numbers with a 0. The compiler treats these as octal numbers.
3) The expression in your if statement is incorrect.
3a) You are using %26amp;%26amp; (and) instead of || (or). A number can't be both less than 1 and greater than 12.
3b) You need to write the variable name once for each expression in your if statement.
Reply:your expression is wrong.
if (Month %26lt; 01 %26amp;%26amp; %26gt; 12);
cout%26lt;%26lt; "Please enter a valid Month in 2 digit format\n";
it should be like
if (Month %26lt; 01 %26amp;%26amp; Month%26gt; 12)
cout%26lt;%26lt; "Please enter a valid Month in 2 digit format\n";
correct similar mistakes.
ur syntex is incorrect.try reading some books or search google for c++ tutorial.
Reply:duh com'on --- if statements will not have """ ; """ semicolen marks .... check it out.
jasmine
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment