Jump to content
  • Advertisement
Sign in to follow this  
phil05

Untitled

This topic is 5456 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I swear there's nothing wrong with this assignment. Can I blame it on the compiler?
// **************************************************************************************************************
// Project: Time Conversion
// Programmer: Phillip Vaira
// Date: October 13, 2004
// Purpose: Get two times and calculate them together, first by gathering the total seconds then convert to time.
// **************************************************************************************************************

// PREPROCESSOR DIRECTIVES
#include <iostream>				// for cin, cout, endl

// PROTOTYPES
long Time_To_Secs(Time t);

// Structure: Time
struct Time
{
public:
	int Hours;
	int Minutes;
	int Seconds;
};

// **************************************************************************************************************
//	Function Name: main()
//  Purpose:  First function called that executes the main program.
//  Parameters: None
//  Return Value: int
//	Last Modified: October 13, 2004.  8:30pm
// **************************************************************************************************************

int main()
{
	Time T1, T2;
	char Choice;

	while (Choice != 'n')
	{
		// ----------------------------------------------------------------------------------------------------------

		std::cout << "Enter a time...\n" << std::endl;

		// Get Hours from User
		std::cout << "Enter Hours: ";
		std::cin >> T1.Hours;

		// Get Minutes from User
		std::cout << "Enter Minutes: ";
		std::cin >> T1.Minutes;

		// Get Seconds from User
		std::cout << "Enter Seconds: ";
		std::cin >> T1.Seconds;
		
		// ----------------------------------------------------------------------------------------------------------
		
		std::cout << "\n\nEnter another time...\n" << std::endl;

		// Get Hours from User
		std::cout << "Enter Hours: ";
		std::cin >> T2.Hours;

		// Get Minutes from User
		std::cout << "Enter Minutes: ";
		std::cin >> T2.Minutes;

		// Get Seconds from User
		std::cout << "Enter Seconds: ";
		std::cin >> T2.Seconds;

		// ----------------------------------------------------------------------------------------------------------

		long T1TotalSecs = Time_To_Secs(T1);			// Convert T1 Structure Variable into Seconds
		long T2TotalSecs = Time_To_Secs(T2);			// Convert T2 Structure Variable into Time

		// Asks User if He/She wishes to do another conversion. If not, exit.
		std::cout << "\n\nDo another (y/n)? ";
		std::cin >> Choice;
	
	}
	
	return 0;
}


// **************************************************************************************************************
//	Function Name: Time_To_Secs()
//  Purpose:  Convert time into seconds.
//  Parameters: None
//  Return Value: long
//	Last Modified: October 13, 2004.  8:54pm
// **************************************************************************************************************

long Time_To_Secs(Time t)
{
	return (t.Hours*3600 + t.Minutes*60 + t.Seconds);		// Get Total Seconds
}




// **************************************************************************************************************
//	Function Name: Secs_To_Time()
//  Purpose:  Convert seconds into time.
//  Parameters: None
//  Return Value: long
//	Last Modified: October 13, 2004.  8:54pm
// **************************************************************************************************************

C:\Program Files\Microsoft Visual Studio\MyProjects\Time Conversion\Time Conversion.cpp(12) : error C2065: 'Time' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\Time Conversion\Time Conversion.cpp(12) : error C2146: syntax error : missing ')' before identifier 't' C:\Program Files\Microsoft Visual Studio\MyProjects\Time Conversion\Time Conversion.cpp(12) : error C2059: syntax error : ')' C:\Program Files\Microsoft Visual Studio\MyProjects\Time Conversion\Time Conversion.cpp(33) : error C2146: syntax error : missing ';' before identifier 'T1' C:\Program Files\Microsoft Visual Studio\MyProjects\Time Conversion\Time Conversion.cpp(33) : error C2065: 'T1' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\Time Conversion\Time Conversion.cpp(33) : error C2065: 'T2' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\Time Conversion\Time Conversion.cpp(44) : error C2228: left of '.Hours' must have class/struct/union type C:\Program Files\Microsoft Visual Studio\MyProjects\Time Conversion\Time Conversion.cpp(48) : error C2228: left of '.Minutes' must have class/struct/union type C:\Program Files\Microsoft Visual Studio\MyProjects\Time Conversion\Time Conversion.cpp(52) : error C2228: left of '.Seconds' must have class/struct/union type C:\Program Files\Microsoft Visual Studio\MyProjects\Time Conversion\Time Conversion.cpp(60) : error C2228: left of '.Hours' must have class/struct/union type C:\Program Files\Microsoft Visual Studio\MyProjects\Time Conversion\Time Conversion.cpp(64) : error C2228: left of '.Minutes' must have class/struct/union type C:\Program Files\Microsoft Visual Studio\MyProjects\Time Conversion\Time Conversion.cpp(68) : error C2228: left of '.Seconds' must have class/struct/union type C:\Program Files\Microsoft Visual Studio\MyProjects\Time Conversion\Time Conversion.cpp(93) : error C2146: syntax error : missing ')' before identifier 't' C:\Program Files\Microsoft Visual Studio\MyProjects\Time Conversion\Time Conversion.cpp(93) : error C2433: 'Time_To_Secs' : 'inline' not permitted on data declarations C:\Program Files\Microsoft Visual Studio\MyProjects\Time Conversion\Time Conversion.cpp(93) : error C2086: 'Time_To_Secs' : redefinition C:\Program Files\Microsoft Visual Studio\MyProjects\Time Conversion\Time Conversion.cpp(93) : error C2059: syntax error : ')' C:\Program Files\Microsoft Visual Studio\MyProjects\Time Conversion\Time Conversion.cpp(94) : error C2143: syntax error : missing ';' before '{' C:\Program Files\Microsoft Visual Studio\MyProjects\Time Conversion\Time Conversion.cpp(94) : error C2447: missing function header (old-style formal list?) Error executing cl.exe. Time Conversion.exe - 18 error(s), 0 warning(s)

Share this post


Link to post
Share on other sites
Advertisement
You've referred to struct Time before implementing it.

// PROTOTYPES
long Time_To_Secs(Time t);

// Structure: Time
struct Time

Move the function definition to below the struct.

Share this post


Link to post
Share on other sites

This topic is 5456 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!