C :: Display Current Time And Date In Program And Use Variable To Store Each Of Values

Feb 16, 2013

i need to display the current time and date in my program and use variable to store each of the time values like

a = 10
b = 29
c = 31

printf(``%d : %d : %d``, a,b,c);

which then give the output as - 10:29:31

How to save the time in variables in C....

i am using C in windows 7 and my complier is Bloodshed Dev C++

View 7 Replies


ADVERTISEMENT

C++ :: Program To Display AM/PM With Current Time?

Feb 14, 2013

I'm trying to display the AM/PM on my program:

Also is there a way to display the time only instead of the date? How will i change the program to display the time in standard 12 hours, instead of 24 hours?

#include <iostream>
#include <time.h>
using namespace std;
int main()
{
time_t tim;
time(&tim);
cout << ctime(&tim);
}

View 1 Replies View Related

C++ :: School Project - Getting Current Date And Time

Dec 30, 2014

I am doing a school project. The project basically is that it records the in and out time of an employee(of an particular company).The employee while checking in or out should enter a unique key generated specially for him so that no one else can check in and out for him.Then referring to the employees position( A worker or a manager or something like that) his total working time each day , for a week and a month is calculated. The company starts at 8 am and ends at 5 pm for 1st shift and for second shift from 3.30 pm to 2.30 am. Plus Saturday and Sunday off. Then after a month the program refers to the working time date stored in a file and calculates his pay(For workers its per hour salary and for managers it aint).

If an employee is consistently late the details are forwarded to the HR account( so that necessary steps are taken).This will support the company log the details of their employees duty time plus give enough detail to take action if someones always late. I'm doing this as a school project and it needn't be of enterprise class and all.. But i want the coding to perform as it should. Also i'm forced to use the old Turbo C++. Now i'm struck in the place where the time of the employees in and out time is logged. This coding does the work

Code:
void main( ) {
clrscr();
char dateStr [9],timeStr [9];
_strdate( dateStr);
cout<<" The current date is "<<dateStr<<'

[Code] ....

I think the second one is better as it not only gives me date but also gives me the day so i can check easily for the weekends. So, how these time functions work.

View 1 Replies View Related

C/C++ :: Save The Current Date And Time Into A Char Array?

Jan 14, 2015

I am trying to use to save the current date and time into a char array using this code:

char current_time(char *date){
time_t result = time(NULL);
date = ctime(&result);
return *date;
}
main{

[Code]...

now when I output the date char array into a txt file I only get gibberish.

View 6 Replies View Related

C/C++ :: Assigning Current Date To Integer Values

Sep 26, 2014

How can i assign current date as integer ?

for example:

today's date 26 Sep 2014 on a computer
i try to make as below
int day=26
int moth=9
int year=2014

I also research i think i will use time.h library surely

View 3 Replies View Related

C/C++ :: How To Get System Date And Time And Display It

Mar 16, 2012

How to get system Date and Time and display it in the format DD/MM/YYYY ??

View 2 Replies View Related

C++ :: Create A Program Which Prompts For User Input Of Current And Birth Date

Sep 27, 2014

I have an assignment in which i must create a program which prompts for user input of current and birth date, which will compare said dates and output if its your birthday or not. I've completed a large portion of it, but cannot figure out how to get the user input of month as an integer such a 2 into February.

#include <iostream>
using namespace std;
class DayOfYear {
public:
void input();

[code]....

View 1 Replies View Related

C++ :: Program Which Takes Date And Time Input From The User

Jan 20, 2013

I am writing a C++ program which takes date & time input from the user. This is then parsed into a struct such as:

struct time
{
short year;
short month;
short day;
short hour;
short min;
};

My question is: how can I convert such a struct into a time_t object, which is an unsigned long giving the time as the number of seconds elapsed since the epoch Jan 1st 1970, 00:00, as set out in time.h.

I am wondering if this can be achieved using the standard library, or whether I just need to write a function to perform the appropriate arithmetic.

View 2 Replies View Related

C :: Program To Take Time And Date Typed By User And Increase It By 1 Minute

Mar 22, 2013

I'm having a problem with my homework. The task is to write a program that will take time and date typed by user, and increase it by 1 minute. I should write 3 functions - first calls second function that updates time and calls third function, if time is 00:00.Time update works, but date update does not.My whole written code:

Code:

#include<stdio.h>
struct DateAndTime {
struct date {
int day;
int month;
int year;

[code]....

I should check if inputs are numbers only, so I tried including isdigit function from ctype.h library, but that didn't work either, after I was trying it for a good hour or so, but I kinda rage quit that...

View 8 Replies View Related

C++ :: Take Values From Text File And Store Them In Variable And Use For Later Calculation

Nov 8, 2013

I have a text file in the form

5502 5202.3
1523 2536.1
1254 1256.2
17846 8956.2 and so on

left one is time and right one is pressure, I need to show the time value as it is but i need to use the pressure value to calculate air speed. I don't know how to use the strings to pick up the list properly. I did the calculation formula for the air speed but i can't pick the pressure value up from the text file. here's what i did:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

[Code].....

View 3 Replies View Related

C/C++ :: Given Person Birth-date Or Any Other Date Will Display Day Of Week

Oct 11, 2012

i'm making a program that, given a person's birthdate or any other date, will display the day of the week of the person was born.

There is this part where it says "use a switch statement to make this calculation, If desired month is 12, add the number of days for November, if desired month is 11 add the number of days for october....

So it's suppose to start with "case 12 :...

I can't figure out what to write for the statement....

View 6 Replies View Related

C++ :: Adding Current Date To The End Of A String

Dec 12, 2014

I need to add the current date to the end of a string but I only need to add the day and not the year or month.

Put the code This is what i have

char date[9];
_strdate(date);
cout << date << endl;

View 1 Replies View Related

C Sharp :: Store Values In Variable Permanently Even After Restarting Machine?

Dec 26, 2013

I want to store values permanently in a variable. The same variable should be able to be edited and saved by user, and whatever it is I need the value of the variable from the last time I modified it, like a database. database because i need this to set my connection string of the database.

View 1 Replies View Related

C++ :: Calculate Approximate Age Of User Based On Current Date And Their Birthday

Nov 23, 2012

I have an extra credit project where I'm supposed to calculate an approximate the user's age based on the current date and their birthday. My problem is that I am not getting the proper date and time. C++ keeps giving me some random date. I looked up c++ time format on the internet because this is extra credit and not in my book.

I am currently using dev C++ 4.9.9.2. Here is my current code :

// included libraries
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <time.h>
#define cls system("cls")
#define pauseOutput system("pause")
void printM(int x);
void age(int m, int d, int y, int &yearAge, int &monthAge, int &dayAge);

[Code] ....

View 1 Replies View Related

C/C++ :: Program To Store Info About Students And Then Display To Screen

Oct 7, 2014

NOTES AT BOTTOM---EXPLANTION, PROBLEMS ETC. SCROLL DOWN

#include <iostream>
#include <iomanip>
#include <string>

[Code]....

I have to write a program that stores information about students and displays results (Formated). Example-

Inputs ( # of students, First and Last name of student, the gender, age, and hieght. (height inputed as inches and outputed as feet and inches))

Student 2
---------
Jett, Joan Female
100 years old 5' 7"

Ive been falling behind a little due to working late and barely having time for my school work. Coming across several issues, one being an error with GENDER (Error C4700: uninitialized local variable 'gender' used:). As well as how to format the end result, i understand that u have to use #include <iomanip>, but am confused on how to format correctly.

View 2 Replies View Related

C++ :: How To Store Variable In Memory When Program Is Closed

Nov 3, 2013

How do you store a variable in memory so that it isn't changed when the program closes? I don't have any experience with this and am just wondering how it is possible. I am creating a program and want it to store your preferences and scores. In a simple program, everything is just reset and I don't want this for my program. How do I store a variable so that it stays the same, but can be changed even when the program is turned off?

View 2 Replies View Related

C++ :: Numbers Game - Store Current Low Number

Dec 14, 2013

I have a program that stores current a low numbers. The Object is to Store the low number every time time one is presented. so say I start the function the first number is the low number. but the trouble im having it once the function is called again it starts over(low number). Is there a way I can keep the function value once the function is called again? Any better way of doing this while keeping function in a class?

double a;
class rff{
public:
void FGH() {
doubleb=0;
cout<< "pick a number"<<endl;

[Code] ....

View 1 Replies View Related

C/C++ :: Get Current Time And Write It To A File?

Jul 19, 2013

i have to write the current time to a file ?how to do it

View 2 Replies View Related

C :: Printing Current TIME At Regular Intervals

Aug 22, 2013

Its a code in module of my program, where I need to print current time (HH:MM:SS) at regular intervals.

Code:
#include<time.h>
#include<stdio.h>
//#include<windows.h>
void delay(unsigned int t){ // loop for some delay.

[Code] ....

But when I am running this code I expect this to print difference in time due to delay. But it doesn't enter the delay loop, why ?

View 5 Replies View Related

C++ :: Date And Time As A String?

Aug 28, 2014

This is what I have:

#include <ctime>
#include <string>
using namespace std;
void date_and_time(string &date, string &time){
time_t current_time;

[Code] ......

Is there a way to make sure that the strings would not contain trailing spaces?

View 1 Replies View Related

C++ :: Program To Display Error Message If Variable Entered Not An Integer

Nov 8, 2013

I need to have a program display an error message if the variable entered isn't an integer but then I want it to cin again. I have this but it doesn't work:

cout << "Enter an Integer: " ;
for (;;) {
cin >> var;
if (!cin) {

[Code] ....

I am not sure how to do what I want and this doesn't work, it just repeats That wasn't an int.. over and over again.

View 8 Replies View Related

Visual C++ :: Program To Display Values From Data File As Image?

Jul 29, 2014

I am writing a program to display values from a data file as an image. But I can only get a blue screen. Here is a small program resembling my code. what I have missed? I only changed OnDraw function.

Code:
void CColorDisplayView::OnDraw(CDC* pDC) {
CColorDisplayDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
CRect rect;

[code].....

View 10 Replies View Related

C++ :: Class Constructor To Create Date And Time?

Mar 13, 2014

I am trying to create two classes: a Date class and a Time class. The Date class has to have three private data members: day, month and year. The Time class should have two private data members:hour and minute. Each class should have two member functions: a constructor and display. I am lost and my code won't run ....

class Date {
private:
int month, day, year;
public:
Date(int m, int d, int y){
month = m;
day = d;
year = y;

[code]....

View 2 Replies View Related

C Sharp :: Show Only Date Not Time In Visual Studio

Feb 1, 2013

How to show only current date not time in webforms in visual studio as for date and time code is

Label1.Text = DateTime.Now.ToString();

What for only date not time

View 3 Replies View Related

C Sharp :: Compare Date In Registry With Local Time?

Feb 2, 2013

The first time my application opens up, it should get the local date out of the System and store this in a registry key. But the second time it should get the date stored in that registryKey and compare it to the date right now.And there is where I am stuck, I just don't know how to get the date out of that key and compare it to the date right now.

This is my code:

RegistryKey key1;  
        private void btnTrial_Click(object sender, EventArgs e) {
            DateTime current = DateTime.Now;  
            key1 = Registry.CurrentUser.OpenSubKey("myKey");    
            if (key1 == null)

[code]....

at the last "if" statement it should compare the date stored in the key with the DateTime.Now.

View 9 Replies View Related

C++ :: Store A Reference Variable As Member Variable Of Interface Object

May 1, 2013

I am having trouble compiling my interface. I am trying to store a reference variable as a member variable of the interface object. Compiler says that the variable has not be initiated correctly.

LCD inherits from VisualInterface which is expecting a DisplayDriver object to be passed in (DisplayDriver is another interface, but thats not important).

I pass the displayDriver object in when LCD is instantiated in maininterfaces.zip

I was pasing it before as a pointer but was told that this could cause me problems with memory leaks and a reference was better, but now I cant seem to get it to compile.

View 11 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved