|
||
|
|||||||
| C/C++ C/C++ Discussion |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Forum Novice
Join Date: Dec 2005
Age: 19
Posts: 130
|
ok for school i gotta write a program that takes a input of a month, input of a date, does a bunch of calculations with is and separate it between the 10's and hundreds's place with a '/' i dont know how to do this but it gets worse... i have to put in IF, THEN statements for each month... with the appropriate number of days, please help i am so lost!!!
p.s. using Borland C++ |
|
|
|
|
|
#2 (permalink) |
|
Forum Novice
Join Date: Dec 2005
Age: 19
Posts: 130
|
heres what i got so far:
i declared my variables as: int day_input, day_output, month_input, month_output; Code:
///////////////////////////////////////////////////////
///// IF, THEN, ELSE Statements /////
///// for months /////
///////////////////////////////////////////////////////
if (x > 12)
{
cout << "Invalid Entry" '\n';
return 1;
}
else
{
CalculationsHere
}
Code:
///////////////////////////////////////////////////////
///// IF, THEN, ELSE Statements /////
///// for days /////
///////////////////////////////////////////////////////
switch(x)
{
case 1 :
{
if ( month_input == 1); // Jan
if (day_input > 31); // days in month
{
cout << "Invalid entry." '\n';
return 1;
}
else
{
}
}
case 2 :
{
if ( month_input == 2); // Feb
if (day_input > 28); // days in month
{
cout << "Invalid entry." '\n';
return 1;
}
else
{
}
}
case 3 :
{
if ( month_input == 3); // Mar
if (day_input > 31); // days in month
{
cout << "Invalid entry." '\n';
return 1;
}
else
{
}
}
case 4 :
{
if ( month_input == 4); // Apr
if (day_input > 30); // days in month
{
cout << "Invalid entry." '\n';
return 1;
}
else
{
}
}
case 5 :
{
if ( month_input == 5); // May
if (day_input > 31); // days in month
{
cout << "Invalid entry." '\n';
return 1;
}
else
{
}
}
case 6 :
{
if ( month_input == 6); // June
if (day_input > 30); // days in month
{
cout << "Invalid entry." '\n';
return 1;
}
else
{
}
}
case 7 :
{
if ( month_input == 7); // July
if (day_input > 31); // days in month
{
cout << "Invalid entry." '\n';
return 1;
}
else
{
}
}
case 8 :
{
if ( month_input == 8); // Aug
if (day_input > 31); // days in month
{
cout << "Invalid entry." '\n';
return 1;
}
else
{
}
}
case 9 :
{
if ( month_input == 9); // Sept
if (day_input > 30); // days in month
{
cout << "Invalid entry." '\n';
return 1;
}
else
{
}
}
case 10 :
{
if ( month_input == 10); // Oct
if (day_input > 31); // days in month
{
cout << "Invalid entry." '\n';
return 1;
}
else
{
}
}
case 11 :
{
if ( month_input == 11); // Nov
if (day_input > 30); // days in month
{
cout << "Invalid entry." '\n';
return 1;
}
else
{
}
}
case 12 :
{
if ( month_input == 12); // Dec
if (day_input > 31); // days in month
{
cout << "Invalid entry." '\n';
return 1;
}
else
{
}
}
}
Last edited by Nine_Coronas; 09-25-2006 at 07:24 PM. |
|
|
|
|
|
#3 (permalink) |
|
Forum Expert
Join Date: Nov 2005
Location: San Diego, CA
Posts: 1,824
|
A switch is the same as a giant set of if statements. From your code the switch(x) looks like it was intented to be the month that you are iffing in the if blocks embedded. You need none of that. You just need the switch/cases. You should also probably read the section in your book about switch statements very carefully.
C// |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|