C/C++ :: Date Validation Accepted By User In Variable
Apr 12, 2012
Some example to validate date accepted by user in variable as follows:
int day;
int month;
int year;
It must validate entered details are correct or not ans
It must check that date is more than System date or not
View 6 Replies
ADVERTISEMENT
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
Sep 17, 2013
My issue is regardless of which date I input its always defaulting to the values I have set in my constructor in my implementation file in the else statement. So the values always default to 3/15/2006 I think its something to do with the logic in my bool function but I may be incorrect.
header
//date.h header
#include <iostream>
#include <string>
using namespace std;
enum DateFormat {numeric, standard, alternative};
const int MIN_YEAR = 1900;
const int MAX_YEAR = 2015;
[Code] ....
View 4 Replies
View Related
Feb 4, 2014
How I could correctly validate user input when the user inputs a numeric value that will be float pay1, pay2, pay3, pay4. However, the if statement that I wrote crashes after I test the validation. I been told that scanf is dangerous, but strtol works best, but how to write a validation with strtol.
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <conio.h>
#define ARRAYSIZE 2
#define FORMAT "First Name Pago1 Pago2 Pago3 Pago4 Total Net"
#define FORMATHEADER "Last Name "
[Code] ....
View 3 Replies
View Related
Dec 20, 2014
I'm trying to validate my input. I require for the user to enter six doubles and if they don't then I want them to re-enter the information. Here is my code:
Code:
while (1>0) {
printf("Please enter arguments in the order: negative mass, positive mass, initial x-position, initial y-position, initial x-velocity, initial y-velocity:
");
if ( scanf("%lf %lf %lf %lf %lf %lf",&MassMinus,&MassPlus,&Pos[0][0],&Pos[0][1],&Vel[0][0],&Vel[0][1]) != 6) {
printf("Not all numbers were assigned!
[Code] .....
At the moment it just waits if you enter less than six numbers and if you enter any more than 6 it just ignores anything after the sixth number (so pretty much does nothing). Also if I entered 1 2 a b 3 4 instead of entering six numbers it would register that as 1 2 0 0 3 4 but I want it to make the user input the numbers again. I'm also aware that "while (1>0)" isn't good programming form but I'm not really sure what to use instead?
View 11 Replies
View Related
Oct 23, 2014
I need validation on what the user inputs. Input should not be an alphabet, empty, and not negative number. This program is for finding the GCD and LCM of multiple numbers.
#include <stdio.h>
void bubble_sort(int numbers[], int len) {
int i, j;
int swapped;
[Code] .....
View 2 Replies
View Related
Aug 24, 2014
What I want is just to make a validation of the users and passwords already set within my array and go to the other form. By the way this form I already made it my start up form on program.cs with the same command I am trying to back to MainForm.
void Button1Click(object sender, EventArgs e) {
string error = "denied";
string[,] usrpass = {{"User1", "pass1"}, {"User2", "pass2"}, {"User3", "pass3"}, {"User4", "pass4"},
{"User5", "pass5"}};
[Code] .....
View 6 Replies
View Related
Jul 19, 2013
How do I prevent user from entering characters or symbols instead of numbers?
int num;
cout<<"Enter a number."<<endl;
cin>>num;
Also, how do I prevent user from entering a number instead of a character?
char c;
cout<<"Enter a character."<<endl;
cin>>c;
View 9 Replies
View Related
Sep 27, 2014
I have a program that reads a text file and then outputs the corresponding transition table according to the regular expression given in the text file. The first line that is read by the code contains the transition table. The subsequent lines of the text files include the strings. I want my code to read the strings in the subsequent lines of the text file and tell me whether the string is accepted or not by the language. Basically, what my code does is that it translates the regular expression to an NFA and then, it translates the NFA to a DFA and then it builds a transition table according to the language.
I have included a special library in my code and I compiled my code from the command line using the following command:
gcc -o lalab lalab.c -lncurses
then, I just run the program like this:
./lalab
Another problem that I have is that my code does not handle the empty transitions, so the program should output a corresponding result when it is fed a regular expression such as a|e. The alphabet of the language is made of {a, b, e} e is the empty transition. The text file that the program reads from includes a regular expression in its first line and strings to be accepted or not in the following lines. Given an input file like this:
(a|b)*a
aaaa
aba
bba
ab
bbb
:frown:
The code should produce an output like this:
yes
yes
yes
yes
no
no
Code:
#include<stdio.h>
#include<conio.h>
#define MAX 20
//=========================================================
struct nfa_state {
int a, b, eps1, eps2;
}NFA[20];
[Code] .....
View 8 Replies
View Related
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
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
View Related
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
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
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
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
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
Jul 24, 2014
The problem is that I need to figure out the user's birthday in months, days, hours, and minutes from today's date.
Here's what I have so far.
#include<iostream>
#include<cmath>
#include<ctime>
using namespace std;
int main() {
int todayDay, todayMonth, todayYear;
int birthDay, birthMonth, birthYear;
[Code] ....
I haven't initialized all the variables, yet. And it's very unfinished. I need to figure out how to convert years from the age into months only. And I need to figure out how to calculate the hours, seconds, and minutes.
View 3 Replies
View Related
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
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
Jun 18, 2013
I have a problem that states: age is an int variable and name is a string.
What are the values of age and name after the following input statements execute.
cin << age;
getline(cin, name);
if the input is:
a. 23 Lance Grant
b. 23 Lance Grant
Ok I have been fooling around with this book all day. My instructer wants us to build the program instead of just saying
a = 23 Lance Grant
How to input B. I mean when I write the program I do not know how to ask for two lines for one input.
View 1 Replies
View Related
Jul 30, 2013
I'm having trouble trying to save a variable from an input of the user. Then use it when i start up another .exe.
If it makes any difference I am using dev c++. I'm using the input as an a or b so some one will put a for english or b for spanish. after that I want to use that info in another if statement of another .exe.
View 1 Replies
View Related
Oct 11, 2013
I am trying to create a global array with user-defined dimensions.the code is:
Code:
int matr_size()
{
int x = 0;
printf("Please enter the number of nodes: ");
scanf( "%d", &x);
printf("There are %d nodes in this simulation.", x);
getchar();
return x;
}
[code]....
I read that an array cannot be defined by a variable in C so I assume that is the issue, but I'm not sure how else to do it. Previously the size was defined by #define NODES and it worked fine but I need this user input.
View 5 Replies
View Related
Apr 6, 2014
My program is designed to read input from the user and then store that input in a structure variable. Whenever i use the cin.getline() function, it comes up with a semantic issue. Here is the code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int DESCRIPTION_SIZE = 100, DATE_SIZE = 20;
struct inventory {
string description[DESCRIPTION_SIZE];
[Code] .....
I left out the other functions. The error reads "no matching member function for call to 'getline'.
View 6 Replies
View Related
Mar 17, 2013
I am getting a compilation error from the code below. It is when i am naming a variable with my user defined type.
#include<iostream>
#include<cstring>
#include<cstdlib>
using namespace std;
class person {
[Code] .....
C:Dev-CppTRIAL.PASS.!!!.cpp In function `int main()':
66 C:Dev-CppTRIAL.PASS.!!!.cpp expected primary-expression before "p"
66 C:Dev-CppTRIAL.PASS.!!!.cpp expected `;' before "p"
74 C:Dev-CppTRIAL.PASS.!!!.cpp `p' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)
83 C:Dev-CppTRIAL.PASS.!!!.cpp `X' undeclared (first use this function)
View 4 Replies
View Related
Dec 3, 2014
I have an if statement that should either match a text variable that the user has entered and a another text variable that has been got from an array but they won't match even if they are the same,Im at a lost with it.
void displayQuestion(int noQuestion, string questionArray[], string answerarray[], string answer, double scorearray, double finalscore){
cout << questionArray[noQuestion] << endl;
cout << "enter an answer " << endl;
cin >> answer;
[Code] ....
View 1 Replies
View Related
Aug 14, 2014
// PROBLEM - Use INPUT VALIDATION so number entered is positive. I can't get it to work
#include <iostream>
#include <iomanip>
using namespace std;
int main(int argc, const char * argv[]) {
// SUM OF NUMBERS
// Enter a positive integer
[Code] ....
View 2 Replies
View Related