Roo
March 16th, 2006, 10:41 PM
ok here is my code i am new to c++ so plz if you can explain a little thanks and i put a commant where i need te help
#include <stdio.h>
#include <time.h>
#include <iostream>
#include <string>
#include <sstream>
void time_delay(int);
main()
{
restart: //In case the user type in alarm wrong.
struct tm *clock;
int tempmin;
int temphour;
char getampm;
std::string gettimetogetuphour;
std::string gettimetogetupmin;
std::string gettimeampm;
std::string tempInput;
std::cout << "set your alarm clock hour:";
std::cin >> tempInput;
std::string::size_type T = tempInput.find(':');
std::string::size_type TT = tempInput.find('/'); //For getting am/pm
if(T != std::string::npos && TT != std::string::npos)
{
gettimetogetuphour = tempInput.substr(0, T);
gettimetogetupmin = tempInput.substr(T+1);
gettimeampm = tempInput.substr(TT+1);
std::stringstream temph(gettimetogetuphour);
std::stringstream tempm(gettimetogetupmin);
std::stringstream tempa(gettimeampm );
temph >> temphour;
tempm >> tempmin;
tempa >> getampm;
/*
here is the problem getampm = the first letter like lets say the user typed am so getampm only = a and not am how can i get it to get the hole thing and be able to user it in a ifstatment something like this
if (getampm != 'am')
{
do something
}
thanks
*/
}
else if(T == std::string::npos || TT == std::string::npos)// Makes sure the user typed the time right.
{
goto restart;
}
std::cout << getampm' ;
for (;;)
{
time_delay(2);// calls the delay function
time_t long_time;
time( &long_time );
clock = localtime(&long_time );
if (temphour == clock->tm_hour && tempmin == clock->tm_min)
{
std::cout << "time to get up\n";
}
}
return 0;
}
// this is the delay function time_delay
void time_delay(int t)
{
long initial,final;
long ltime;
initial=time(<ime);
final=initial+t;
while (time(<ime) < final);
return;
}
#include <stdio.h>
#include <time.h>
#include <iostream>
#include <string>
#include <sstream>
void time_delay(int);
main()
{
restart: //In case the user type in alarm wrong.
struct tm *clock;
int tempmin;
int temphour;
char getampm;
std::string gettimetogetuphour;
std::string gettimetogetupmin;
std::string gettimeampm;
std::string tempInput;
std::cout << "set your alarm clock hour:";
std::cin >> tempInput;
std::string::size_type T = tempInput.find(':');
std::string::size_type TT = tempInput.find('/'); //For getting am/pm
if(T != std::string::npos && TT != std::string::npos)
{
gettimetogetuphour = tempInput.substr(0, T);
gettimetogetupmin = tempInput.substr(T+1);
gettimeampm = tempInput.substr(TT+1);
std::stringstream temph(gettimetogetuphour);
std::stringstream tempm(gettimetogetupmin);
std::stringstream tempa(gettimeampm );
temph >> temphour;
tempm >> tempmin;
tempa >> getampm;
/*
here is the problem getampm = the first letter like lets say the user typed am so getampm only = a and not am how can i get it to get the hole thing and be able to user it in a ifstatment something like this
if (getampm != 'am')
{
do something
}
thanks
*/
}
else if(T == std::string::npos || TT == std::string::npos)// Makes sure the user typed the time right.
{
goto restart;
}
std::cout << getampm' ;
for (;;)
{
time_delay(2);// calls the delay function
time_t long_time;
time( &long_time );
clock = localtime(&long_time );
if (temphour == clock->tm_hour && tempmin == clock->tm_min)
{
std::cout << "time to get up\n";
}
}
return 0;
}
// this is the delay function time_delay
void time_delay(int t)
{
long initial,final;
long ltime;
initial=time(<ime);
final=initial+t;
while (time(<ime) < final);
return;
}