C/C++ :: Making A Date Format Input?

Dec 16, 2014

how my code should work is a console screen in which the user enters a date using format dd/mm/yyyy

Regardless of logical errors (checking days if bigger than 31 or negative values or.. etc) My code should be able to validate the following:

- if the user enters a letter, the program should output an error message

- if the user typed the date as 8/2/2014 the program should convert it to 08/02/2014 without returning an error message

Here's my code so far, I really can't find the bugs in it

#include<iostream>
using namespace std;  
main(){
 char d[2], m[2], y[4], br1, br2, dx, mx;
 bool end, nobr1, nobr2;

[code]....

as you notice, I tried two different validating formats in the days and months, unfortunately they both failed..

Here's how my program is outputting so far:

View 3 Replies


ADVERTISEMENT

C++ :: Getting User Input In Date Format

Oct 26, 2014

So I have a programming assignment which is for getting a user input in the format of m/d/yyyy. This is stored as d/m/yyyy. I have been able to code all the rest of the requirements of the program but the thing that is giving me trouble is this. The year is allowed to go from 1-3000. The format of the displayed date is:

a zero-filled, two-digit day number, a dash, full name of month, a dash, zero-filled, four-digit year.

I am able to use a switch statement in order to get my name of the month. What I am struggling to figure out is the whole zero filled two digit day and zero filled four digit year. From the way the input is store it appears to me that it will be stored as yyyy which means if you were to enter 0001 for year 1 then it should output it as that (this is an assumption based on format). What I don't get is that the day is entered and stored as d which means if you put in 12 how would it be stored. However if you put in 6 to print the output I would need to add a zero and I dont know how to do that either.

Here is the code for getting the input. The function must stay formated this way as per the instructor. The / is stored but ignored hence the char for second and fourth since / is a char

Code:
void getDate (int& day, int& month, int& year){
char second;
char fourth;
cout << "Please enter a date in the format of m/d/yyyy" << endl;
cin >> month >> second >> day >>fourth >> year;
}

View 4 Replies View Related

C++ :: Program To Enter Today Date In Certain Format?

Apr 2, 2013

I want to create a program where you enter today's date, in the following format: 02/04/2013. As well as your birth date in the following format: 27/09/1994. After doing that I want to assign the day, month and year of the present date, as well as the day, month and year of the birth date in to their own variables (for example, Day, Month, Year), and then calculate your age.

I have tried doing this with cin.get(), but this method is way too long, and I'm looking for a shorter method

View 2 Replies View Related

C Sharp :: How To Convert Date In Integer Format To DateTime

Jun 8, 2013

How do I convert date in integer format to DateTime without using DateTime?

I have tried:

Regex regex = new Regex(@"^(0[1-9]|1[012])(0[0-9]|1[0-9]|2[0-9]|3[01])(1[789]|[2-9][0-9])dd+$");
if (regex.IsMatch(txt_fromdate.Text) == true)
            {
                DateTime dt = DateTime.ParseExact(txt_fromdate.Text, "MMddyyyy", null);
            }

View 1 Replies View Related

C/C++ :: How To Ask A User To Enter Date And ISBN Number In Specific Format

Dec 4, 2014

I don't know how to ask the user to enter the date in this format (DD/MM/YY) and ISBN number with hyphens.

After user enter date and ISBN number, it should look like this:

Date: 5/24/12
ISBN: 0-000-12345-0
#include <iostream>
#include <string>
using namespace std;
int main() {
string date;//MM/DD/YY Format

[Code] ....

View 7 Replies View Related

C++ :: Input Validation For Date?

Jul 19, 2013

How do you do the input validation for date? I used:

char rec.date[SIZE];
cout<<"date"<<endl;
cin.getline(date,SIZE);

I want the user to write in this format (mm/dd/yy)

View 3 Replies View Related

C++ :: Input Date And Get Day Of The Week

Oct 23, 2014

How can I check for an invalid date when I run the program? I am trying to enter a conditional statement that checks for a valid or invalid date.

Programing Question: Write a program that inputs a date (e.g., July 4, 2008) and outputs the day of the week that corresponds to that date. Here is what I Have. The program runs. I need it to loop around.

#include <iostream>
using namespace std;
const int JANUARY = 1;
const int FEBRUARY = 2;
const int MARCH = 3;
const int APRIL = 4;

[Code] ....

View 1 Replies View Related

C++ :: Input Date Field In A Comment

Mar 11, 2014

I am building a template for CodeBlocks, which pre-write some includes, the main skull and a header.

This header looks like that :
/**
* @Author Me
* @Description Brief description
* @Date ??
*/

I would like to put the current Date, just after the line @Date, is-it possible ? And if yes, it-is possible to put a field @FileName which copy the filename into the comment ?

View 2 Replies View Related

C# :: Check Input Date Between 2 Dates (not SQL)

Oct 8, 2014

In my WinForm, Our client insists to use Textbox instead of DateTimePicker field, and they want to input in ddmmyy format.

Using Visual Studio 2010 C# 4.0.

PC date time setting: GMT +08:00 dd-MMM-yy.

Assumed today date is 291014 (29-Oct-14).

CodeBehind:

DateTime inputDate;
// the WinForm allows user to input date not earlier than 2 years before today date and not more than 1 months from today date too.
//Assumed I input date as 261014 (26-Oct-14)
if(DateTime.TryParseExact(input, "ddMMyy", new System.Globalization.CultureInfo("en-US"), System.Globalization.DateTimeStyles.None, out inputDate)) {
DateTime minDate = DateTime.Now.AddMonths(-24);//Assumed it is 29-Nov-14
DateTime maxDate = DateTime.Now.AddMonths(1);//Assumed it is 29-Oct-12

I tried many methods but none works (I have checked many threads/forums also).

//Method 1
if(inputDate >= minDate && inputDate <= maxDate)
return true

//Method 2: B return true but A ***always*** return false, Why??
if (inputDate >= minDate)
A = true;

[code]....

View 1 Replies View Related

C++ :: Input Date - Output Day Of The Week

Apr 3, 2013

I'm just starting coding and I just want it to input a date, then output a day of the week.

Code:
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int startday = 0, sm = 1, sd = 1, sy = 2000, cm = 0, cd = 0, cy = 0;
cout << "Please enter the current month, day, and year: ";

[Code] ....

View 1 Replies View Related

C Sharp :: Input String Was Not In Current Format?

Nov 18, 2012

error is giving.

int ages = 0;
ages = int.Parse(textBox2.Text);  
if(textBox2.Text == "")
{
MessageBox.Show("Age Blank  ......");  
}
else if (ages >= 5 || ages <= 9)
{
MessageBox.Show("age must be 5 to 9 only");
}

View 1 Replies View Related

C Sharp :: Input String Was Not In Correct Format

Apr 28, 2012

List<Byte> Pt_split(string plain)  {
            List<Byte> pb = new List<Byte>();
            // Byte p;
            string p;
            int temp = 0;
            if (plain.Length % 2 != 0)

[Code] ....

View 2 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++ :: Write Program That Uses Boost Library To Input String Date?

Apr 23, 2014

I'm trying to write a program that uses the Boost library to input a string date in the format mm/dd/year and outputs to the string its corresponding day of the week. I wrote the program that I thought would accomplish this, but it doesn't seem to work. Below is the code I wrote:

#include <string>
#include <iostream>
#include "boost/date_time/gregorian/gregorian.hpp"

[Code]....

When I compile this using codeblocks it gives me the error "In function `ZN5boost9date_time19month_str_to_ushortINS_9gregorian10greg_monthEEEtRKSs':|
C:Users
osaDesktop est3........Liboost_1_55_0oostdate_timedate_parsing.hpp|67|undefined reference to `boost::gregorian::greg_month::get_month_map_ptr()'". And it takes me to the file date_parsing.hpp and highlights line 67. I don't understand why this isn't working.

View 3 Replies View Related

C++ :: Making Diamond Out Of Asterisks Based On Given Odd Integer Input

Sep 6, 2014

I have been tasked with making a diamond out of asterisks based on a given odd integer input. For some reason the bottom half of my diamond will not print. I'm not sure as to why.

Here is my code:

#include "stdafx.h"
#include <iomanip>
#include <iostream>

using namespace std;
int _tmain(int argc, _TCHAR* argv[]){

[Code] ....

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/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++ :: Two Date Structures Sharing Same Date

Mar 28, 2014

I have two date/time structures which I'm populating, but when I populate the second one it sets the same values in the first. This is what I've got so far

tm *FirstDate = gmtime(&now);
tm *SecondDate = gmtime(&now);

cout <<"Enter your first date in the format dd/mm/yyyy" << endl <<">";
getline (cin,tempstring);

[Code] .....

View 2 Replies View Related

C/C++ :: Taking String As Input And Making It As Whole Array (string Literal)

Oct 19, 2014

Very new to programming, and I know that there must be another way on inputting a string into each array cells not by just inputting it one by one, but as a whole. My code at the meantime is: [URL]

View 1 Replies View Related

C++ :: Converting One Format To Another?

Apr 7, 2013

I am in a c++ class and my group is having a hard time making this work... It keeps saying that 'fileOne.open' isn't working.

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

[Code]....

View 3 Replies View Related

C :: Editing Image In PPM Format

Mar 10, 2014

I'm trying to edit an image by multiplying the red component of each pixel by 10 and leaving the other components (green and blue) untouched. I'm not really sure how I'm supposed to edit the pixels one by one. I have this so far. I think there is something wrong with my ppm header as well. Is there a way to make a ppm header without specifying the bounds so that it conforms to the image you are putting in?

Code:

#include <stdlib.h>
#include <stdio.h>
#define PICTURE_FILE 1
#define MIN_ARGS 2
#define h 768
#define w 1024
void solve(FILE *in_picture, FILE *out_picture)

[Code] .....

View 6 Replies View Related

C# :: Change File Format

Jun 20, 2013

I have installed VS 2010 and VS 2012. VS 2012 uses SqlServer CE 3.5 and VS 2012 uses SqlServer CE 4.0.The problem is that when a project uses a 3.5 file it tries to open it with 4.0 even if the app.config says to use the 3.5 provider. The version of the assembly is pulled right out of the GAC. I uninstalled 4.0 and the reference auto updated its version to 3.5.1. However after installing 4.0 again it changes to 4.0. The error I am getting is that 4.0 cannot open a 3.5 file....they changed the file format from 3.5 to 4.0 and they are not compatible.

View 2 Replies View Related

C :: Printing Of A File In Different Format?

Sep 13, 2013

The requirement is to capture statistics of uuid occurrences for ALIVE/SEARCH/BYEBYE (it can be all 3, combinations of 2 each, or one alone) in a dynamically populated file in run time.

I am able to print all 3 combinations, but not in combination of 1 or 2 e.g.

If my input.txt is like this :

uuid:22314754-a597-490b-8a93-02cfae01036b ALIVE 16
uuid:22314754-a597-490b-8a93-02cfae01036b BYEBYE 8
uuid:22314754-a597-490b-8a93-02cfae01036b SEARCH 8
uuid:50e65653-7525-485d-83bf-d293558c4264 ALIVE 32
uuid:50e65653-7525-485d-83bf-d293558c4264 BYEBYE 8
uuid:50e65653-7525-485d-83bf-d293558c4264 SEARCH 132

[Code]...

Code:

#include<stdio.h>
#include<string.h>
struct uid
{
char uid_val[100];
char state[100];
int temp_count;
int alive_count;
int search_count;

[Code]...

Gives the following output ->output.txt)

Device ID ALIVE BYEBYE SEARCH
uuid:22314754-a597-490b-8a93-02cfae01036b 16 8 8
uuid:50e65653-7525-485d-83bf-d293558c4264 32 8 132
uuid:55076f6e-6b79-4d65-6497-180373763bc1 113 112 111
uuid:T0100203354 1 2 3

I want to generalize the code such that uuid occurrence does not have to be all 3 (ALIVE/SEARCH/BYEBYE), the occurrences can be any combination and code should work. e.g my code gives wrong results when input.txt contains the following:

uuid:22314754-a597-490b-8a93-02cfae01036b BYEBYE 8
uuid:22314754-a597-490b-8a93-02cfae01036b SEARCH 8
uuid:50e65653-7525-485d-83bf-d293558c4264 ALIVE 32
uuid:50e65653-7525-485d-83bf-d293558c4264 BYEBYE 8
uuid:55076f6e-6b79-4d65-6497-180373763bc1 ALIVE 113
uuid:55076f6e-6b79-4d65-6497-180373763bc1 BYEBYE 112
uuid:55076f6e-6b79-4d65-6497-180373763bc1 SEARCH 111
uuid:T0100203354 BYEBYE 2

I am using ubuntu for gcc/g+ compiler.

View 1 Replies View Related

C++ :: How To Convert Characters To Hex Format

Oct 4, 2014

Is my understanding correct?

Ascii 'a' = 61 (Hex)
Ascii '0' = 30 (Hex)

So this is how we convert characters to hex.

Integer 0 = 0 (Hex), because it's not a character but an integer.

View 8 Replies View Related

C/C++ :: How To Format A Calendar Table

Apr 27, 2014

I am trying to format a Gregorian Calendar that accepts only the year as a user input, but I want the display to show 3 months on one row. I can get January to display correctly, but the February and March months do not.

I think my loop inside of my calendar1 function specifically is the issue:

//Is day before Sat? Else start next line Sun.
if ( ( day + daycode ) % 7 > 0 )
cout << right << setw(3);

[Code]......

View 1 Replies View Related

C/C++ :: Format Output Into Columns?

Apr 8, 2015

My output right now is:

Enter first prime numbers that will be used or -1 to end: 20
Twin Prime Number : (3,5)
Twin Prime Number : (5,7)
Twin Prime Number : (11,13)
Twin Prime Number : (17,19)

But what I want is:

1. {3;5} 2.{5,7} 3.{11,13}

4. {17,19}

else if (i - prime_number == 2)
{
cout << "{" << prime_number << ";" << i << "}" << endl << endl;
prime_number = i;
}

View 1 Replies View Related







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