I'm using Dev-C++ and I tried to compile the below code:
Code:
#include <iostream>
using namespace std;
int validnum(int lower,int higher);
int main()
{
cout << "Please enter your birthday. Enter the year: ";
int year = validnum(1990,1998);
cout << "Enter the month: ";
int month = validnum(1,12);
int date = 0;
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
date = validnum(1,31);
break;
case 4:
case 6:
case 9:
case 11:
date = validnum(1,30);
break;
case 2:
if (year%4 == 0)
{
date = validnum(1,29);
break;
}
else
{
date = validnum(1,28);
break;
}
}
cout << endl
<< "Your birthday is on "
<< date
<< "."
<< month
<< "."
<< year
<< "."
<< endl;
system("PAUSE");
return 0;
}
int validnum(int lower,int higher) //function to check whether number is valid
{
int num = 0;
cin >> num;
while((num < lower)||(num > higher)) //tell user that number is invalid
{
cout << "Your number is invalid, please try again: ";
cin >> num;
}
return num;
}
but it resulted in the following errors:
1. too many filenames. Type cc1plus -- help usage info.
2.unrecognized option 'quieu'
3.output filename specified twice
I thought this kind of errors might be a compiler problem, so I cheated and look at the book's answer key and inserted the code in the compiler:
Code:
#include <iostream>
using namespace std;
int validNum(int lower, int upper);
int main()
{
cout << "Enter your birthdate here. Enter the year first. " << endl;
int year = validNum(1900, 1998);
cout << "Now the month. ";
int month = validNum(1, 12);
cout << "Now the date. ";
int date = 0;
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
date = validNum(1, 31);
break;
case 4:
case 6:
case 9:
case 11:
date = validNum(1, 30);
break;
case 2:
if(0==year%4)
date = validNum(1, 29);
else
date = validNum(1, 28);
}
cout << endl
<< "We have established that your date of birth is "
<< month << "/" << date << "/" << year << "." << endl;
return 0;
}
int validNum(int lower, int upper)
{
int data = 0;
cout << "Please enter an integer between " << lower << " and " << upper << ": ";
cin >> data;
while(data < lower || data > upper)
{
cout << "Invalid entry; please re-enter: ";
cin >> data;
}
return data;
}
As I have thought, the compiler returned the same errors. Is there anyway to fix this problem? Or must I change my compiler?