Click to See Complete Forum and Search --> : Need help with Military=>Standard Time


isochar
04-01-2002, 01:43 PM
*deleted*

dighn
04-01-2002, 01:53 PM
i noticed a couple of things. they probably are not the only problems but anyway try them and see what you get


- for function definitions, you need the type in the header. eg you canot simply write "void getData (hours, colon, minutes)". each parameter needs a type

- i believe void getData (int&, char, int); is supposed to be void getData (int&, char, int&);

- i believe you want the while loop to continue when the input is invalid right? the innput would be invalid if hour is not between 0 and 23 or minute is not between 0 and 59. so the correct logic to use in this case would be
while((hour<0&&hour>23)||(minute<0&&minute>59))

isochar
04-01-2002, 08:14 PM
Everything seems to be fine now, EXCEPT I get this error 4 times:

militarytimetostandardtime.cpp(59) : error C2447: missing function header (old-style formal list?)
militarytimetostandardtime.cpp(70) : error C2447: missing function header (old-style formal list?)
militarytimetostandardtime.cpp(92) : error C2447: missing function header (old-style formal list?)
militarytimetostandardtime.cpp(100) : error C2447: missing function header (old-style formal list?)

My only other major problem is how to run the loop again if the user chooses Y/y...

BTW, is there anyway to maintain my formatting when I post it here?

// Step 1: Request user inputs Military Time to convert to Standard Time
// Step 2: Analyze Military Time inputed to see if hours are greater than or
// equal to 00 and less than or equal to 23, and minutes are greater than
// or equal to 00 and less than or equal to 59
// --- if true, then continue to step 3
// --- if false, then stop and output error
// Step 3: Convert Military Time to Standard Time
// --- if time equal to 00:00 to 00:59, then convert to 12:xx AM
// --- if time equal to or between 01:00 and 11:59, then do not covert
// and add AM to the output
// --- if time equal to or between 12:00 and 12:59, then do not convert
// and add PM to the output
// --- if time equal to or between 13:00 and 23:59, then convert by
// subtracting 12 from the hours variable and and PM to the output
// Step 4: Output the Military Time Inputted and the converted Standard Time
// Step 5: Ask if another time needs to be inputted
// --- if true, then repeat steps 1 thru 4
// --- if false, then terminate program
//
//************************************************************ ******

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int hours;
int minutes;
int newhours;
char colon;
string AorP;

void getData (int&, char, int&);
void convert (int&, int&, string&);
void printTime (int&, char, int, int&, string&);
void runAgain ();

int main()
{
getData (hours, colon, minutes);
while ((hours >= 0 || hours <24) && (minutes >= 0 || minutes <= 60))
{
convert (hours, newhours, AorP);
printTime (hours, colon, minutes, newhours, AorP);
runAgain ();
getData (hours, colon, minutes);
}
return 0;

}

//*****************************************************
void getData (int hours, char colon, int minutes);
{
cout << "Please input the Military Time you would like to convert in" <<
" HH:MM format." <<
" The hours inputed must be greater than or equal to 00, and" <<
" less than or equal to 23." << " The minutes must be greater" <<
" than or equal to 00, and less than or equal to 59." << endl;
cin >> hours >> colon >> minutes;
}

//*****************************************************
void convert (int hours, int newhours, string AorP);
{
if (hours == 00)
{
newhours = 12;
AorP = "AM";
}
if (hours >= 01 && <= 11)
{
AorP = "AM";
}
if (hours = 12)
{
AorP = "PM";
}
if (hours >= 13 && <= 23)
{
newhours = (hours - 12);
AorP = "PM";
}
}
//*****************************************************
void printTime (int hours, int minutes, int newhours, string AorP);
{
cout << "The inputed military time was " << hours << colon << minutes
<< endl;
cout << "The converted standard time is " << newhours << colon << minutes
<< endl;
}
//*****************************************************
void runAgain ();
{
char runChar;
cout << endl << "Would you like to run another conversion? " << endl;
cout << "Please enter Y/y or N/y: " << endl;
cin >> runChar >> endl;
if (runchar == 'Y' || runchar == 'y')
{


}
else
{
cout >> "Thank you for running the conversion calculator!" << endl;
}
}
//*****************************************************

dighn
04-01-2002, 11:58 PM
the reason is the parameter types of the function definitons need to be EXACTLY the same as the ones in the prototype

eg.

you have void getData (int&, char, int&); as the prototype
and for defintion you have void getData (int hours, char colon, int minutes);


they do not correspond
void getData (int hours, char colon, int minutes); needs to be void getData (int& hours, char colon, int& minutes);

you can fix the rest :)

as for run again. you could have a do while loop that contains all the stuff that's in main() right now and decide to loop or not based on a return from runAgain() (eg bool runAgain() which returns true or false)

isochar
04-03-2002, 09:30 PM
Ok, the revised program is compiling fine, but when I build and run it I get this error message:

--------------------Configuration: militarytimetostandardtime - Win32 Debug--------------------
Linking...
militarytimetostandardtime.obj : error LNK2001: unresolved external symbol "void __cdecl printTime(int &,char,int,int &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &)" (?printTime@@YAXAAHDH0AAV?$basic_stri
ng@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
Debug/militarytimetostandardtime.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

militarytimetostandardtime.exe - 2 error(s), 0 warning(s)


// Step 1: Request user inputs Military Time to convert to Standard Time
// Step 2: Analyze Military Time inputed to see if hours are greater than or
// equal to 00 and less than or equal to 23, and minutes are greater than
// or equal to 00 and less than or equal to 59
// --- if true, then continue to step 3
// --- if false, then stop and output error
// Step 3: Convert Military Time to Standard Time
// --- if time equal to 00:00 to 00:59, then convert to 12:xx AM
// --- if time equal to or between 01:00 and 11:59, then do not covert
// and add AM to the output
// --- if time equal to or between 12:00 and 12:59, then do not convert
// and add PM to the output
// --- if time equal to or between 13:00 and 23:59, then convert by
// subtracting 12 from the hours variable and and PM to the output
// Step 4: Output the Military Time Inputted and the converted Standard Time
// Step 5: Ask if another time needs to be inputted
// --- if true, then repeat steps 1 thru 4
// --- if false, then terminate program
//
//************************************************************ ******

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int hours;
int minutes;
int newhours;
char colon;
string AorP;
bool test;

void getData (int&, char, int&);
void convert (int&, int&, string&);
void printTime (int&, char, int, int&, string&);
void runAgain (bool test);

int main()
{
while (runAgain == 0)
{
getData (hours, colon, minutes);
while ((hours >= 0 || hours <24) && (minutes >= 0 || minutes <= 60) && (test == true))
{
convert (hours, newhours, AorP);
printTime (hours, colon, minutes, newhours, AorP);
runAgain (test);
getData (hours, colon, minutes);
}
cout << "Thank you for running the Multiplication Assistance Program." << endl;
}
return 0;

}

//*****************************************************
void getData (int& hours, char colon, int& minutes)
{
cout << "Please input the Military Time you would like to convert in" <<
" HH:MM format." <<
" The hours inputed must be greater than or equal to 00, and" <<
" less than or equal to 23." << " The minutes must be greater" <<
" than or equal to 00, and less than or equal to 59." << endl;
cin >> hours >> colon >> minutes;
}

//*****************************************************
void convert (int& hours, int& newhours, string& AorP)
{
if (hours == 00)
{
newhours = 12;
AorP = "AM";
}
if ((hours >= 01) && (hours <= 11))
{
AorP = "AM";
}
if (hours = 12)
{
AorP = "PM";
}
if ((hours >= 13) && (hours <= 23))
{
newhours = (hours - 12);
AorP = "PM";
}
}
//*****************************************************
void printTime (int& hours, int minutes, int& newhours, string& AorP)
{
cout << "The inputed military time was " << hours << colon << minutes
<< endl;
cout << "The converted standard time is " << newhours << colon << minutes
<< endl;
}
//*****************************************************
void runAgain (bool test)
{
char runChar;
cout << endl << "Would you like to run another conversion? " << endl;
cout << "Please enter Y/y or N/n: " << endl;
cin >> runChar;
if (runChar == 'Y' || runChar == 'y')
{
test=true;
}
else
{
test=false;
}
}
//*****************************************************

dighn
04-03-2002, 10:22 PM
remember, the function prototypesès types must be exactly the same as your declarations. try to find the problem yourself, look through it carefully.