This is supposed to play a file (That I can do)
Save a file (That I can do)
Load a file (That I can do)
Get system time (That i can't do)
Basically what's supposed to happen is if system time = wished to be woken time then play an mp3 file or something...
Problem is I can't get the time in a variable, I figured a string would be best to avoid am/pm issues... but now i just want it to work.. i've spent maybe almost 2 hours... and its frustrating me.. i've tried everything i can think of... and google too. I'm on XP.. using Dev CPP
//Alarm Clock By: Johnathan Brown
#include <iostream>
#include <fstream> //Might use a load previous time feature.. not sure yet
#include <string>
int main() {
usingnamespace std;
//Variables
int choice = 0;
string current;
string wake;
//I like my name.. lol.. so I put it in
cout << "*************Johnny's Alarm Clock**********" << endl;
cout << "Version 1.0" << endl;
//MENU
while (choice < 1 || choice > 3)
{
cout << "1) Set a time to wake up to" << endl;
cout << "2) Retrieve last used time to wake up to" << endl;
cout << "3) Exit" << endl;
cout << "What option would you like: ";
cin >> choice;
switch (choice)
{
/*Here lies the problem.. I have no errors and its not complete yet
but I can't get it to get the system time... and i've tried checking to
see if it has it and it doens't.. what I need is the system time in
a type of variable I thought i would need a string to avoid am/pm issues
but this isn't working out..
*/
case 1:
system("cls");
cout << "Be sure to set your windows time before doing this" << endl;
system("pause");
system("cls");
cout << "The format is HH:MM am/pm for example 07:00 am" << endl;
cout << "What time would you like to wake up? ";
getline(cin, wake); // <-- UPDATED with "firedraco's" advice
system("pause");
system("time /t");
getline (cin, current);
system("cls");
cout << "Current time is " << current;
cout << "Wake up time is " << wake;
system("pause");
break;
// DONT WORRY BOUT THIS PART YET
case 2:
system("cls");
cout << "dont worry";
break;
//DONT WORRY ABOUT THE ABOVE YET
case 3:
cout << "Ok, Thank you!!!"; //Exit
system("pause");
return 0;
break;
default:
cout << "That is not a number between one and 3" << endl;
system("pause"); //In case number is outta range
system("cls");
break;
}
}
system("pause"); //End of program
return 0;
}
The way you have it set up it is prompting the user for the time, (not correctly though, but the above will fix that), and next it gets data from cin into a string called current (which is the correct way), but since it is getting from cin you will need to have the user input the current time...
If you want to get the time form the system...it's actually a lot harder then (I think) it should be...go look up tm_struct and the related stuff.
I've updated the program according to your first post (strings).. I still can't get system time in format HH:MM AM/PM... the tm_struct looks complicated.. is there an alternate.... because I think I can work a quicker console job with batch... or even in vb.net.. btw.. I've noticed with the CIN update... i now get this in CMD.. it doesn't give the chance for an input time to wake up at
The format is HH:MM am/pm for example 07:00 am
What time would you like to wake up? Press any key to continue . . .
maybe theirs a header I can use.. and i'm still a beginner at C++ programming... would it be possible to turn this into a function.. or a class so next time i want the time in a program i won't have to go through the whole tm_struct (which i currently don't understand)
although about the above quote.. it seems to work again remembering the wake variable if i do this cin >> wake;
and then add an underscore to format so its this now HH:MM_am/pm
.. still can't get system time though
Yes, like I said, cin stops at the first whitespace it sees...that is why you use getline(cin, myString) instead...if it skipped the first whitespace, the data is still in the buffer when it gets to the next cin>> then skips through it because it just reads the data.
I think I'm going to give this alarm clock a break for now. I thought it would be a basic thing for a C++ newb, but it's way more than I was asking for, I figure I could work on organizing my code into functions and classes, it is quite messy, but all this help won't go to waste, I'm not giving up just pausing. Thanks all. (When done source code for v1.0 will be posted for all to see)