Go Back   RunUO - Ultima Online Emulation > Developer's Corner > Programming > C/C++

C/C++ C/C++ Discussion

Reply
 
Thread Tools Display Modes
Old 09-25-2006, 05:56 PM   #1 (permalink)
Forum Novice
 
Join Date: Dec 2005
Age: 19
Posts: 130
Default i need help with how i should go about writing this program

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++
Nine_Coronas is offline   Reply With Quote
Old 09-25-2006, 07:17 PM   #2 (permalink)
Forum Novice
 
Join Date: Dec 2005
Age: 19
Posts: 130
Default

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
		{
		
		}
	}
}
i put return 1; i donno if thats how i'm suppoesd to make it loop back and start over or not.. and the else... i want it to like go do the calculations

Last edited by Nine_Coronas; 09-25-2006 at 07:24 PM.
Nine_Coronas is offline   Reply With Quote
Old 10-06-2006, 10:11 AM   #3 (permalink)
Forum Expert
 
Courageous's Avatar
 
Join Date: Nov 2005
Location: San Diego, CA
Posts: 1,824
Default

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//
Courageous is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5