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


ADVERTISEMENT

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++ :: 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

Visual C++ :: Letting User Enter A Character On Specific Line And Place?

Aug 8, 2014

How can I create in my C++ program so a user can paste a text and then choose a character on specific line and place?. The above thing isn't that important. I just want to place a character on a specific line and place.

I mean something like this:

Enter a character:

You choosed " / "

On which line do want the character?

You choosed "Line 1 and 2"

Where do you want the the to appear on the line? (left or right)

You choose left.

Results:

Line 1. / hello

Line 2. / hello

View 8 Replies View Related

C :: Program That Allow User To Enter A Number N And Print Nth Prime Number

Nov 3, 2013

I need to write a program that will allow the user to enter a number "n" and the program tell you that the nth prime number is .....

EXAMPLE

user enters 55

printf("The 55th prime number is %i", variable");

View 1 Replies View Related

C++ :: Program That Ask User To Input 5 Books With ISBN Title Of Book With Author

Jan 29, 2013

So I was asked to create a C++ program that will ask the user to input 5 books with the ISBN, Title of the book and author/s. It will ask for 3 authors, if the book has only one author, you should leave "author 2 and author 3" blank and display only one author. Thing is... I'm having a problem with the if else condition at the last part of my program. I cant seem to make it work.

#include <iostream>
#include <cstring>
#define SIZE 5
using namespace std;
int i;

[Code]...

View 9 Replies View Related

C++ :: How To Restrict User To Enter Four Digit Number Only

Aug 22, 2014

I am trying to write up something to have a user to enter a four digit number. Only four digits, Ex: 0001, 0116, or 9999. There is no getting around the selection 0001 or 0002. I understand if not done correctly, the first three 0's will be ignored.

I've been just playing around with what I have below but I just don't remember how to do it nor can I find a good example online to figure it out. I know it is not correct just typing to try to remember. I am aware that it is gibberish right now, this is just me brainstorming.

int number;
cout<<("Please enter the four digit number(Ex: 0001):
");
cin>> setw(2) >> number;
cout<<)"Please enter four digit date. Two digits for month and two digits for year:
");
cin>> date;
if (number< || number > 30)
cout << "Invalid choice. Try again." << endl;
cin.clear();

View 2 Replies View Related

C++ :: Program That Asks User To Enter Even Number Only

Mar 23, 2014

Write a C++ program that asks the user to enter an even number only. If the user enters an odd number the program should use input validation to ask the user to enter another number.

- The user can enter as many numbers as he wants

- The program should also keep a count of how many numbers entered and display how many odd and even numbers entered.

View 1 Replies View Related

C++ :: Basic Calculator - User Will Have To Press Enter After Every Number

Mar 22, 2013

I'm stuck because I can make the calculator just find but the user will have to press enter after every number, what is s solution to this?

#include <iostream>
#include <string>
using namespace std;
int a = 1, b, c;
string symbol;
int multiplyFunction();

[Code] .....

View 6 Replies View Related

C++ :: Write Program That Prompts User To Enter Item Number

Jun 27, 2013

Write a program that prompts the user to enter an item#, the program should determine if the item is in the file and print the price of the corresponding item. If the item is not in the file an error message should be printed.

All I have so far is

string item_no=0;
cout<<"Enter a item#";
getline(cin,item_no);
if stream openData;

I need to finish the rest in pseudo code

View 2 Replies View Related

C/C++ :: Creating Program That Allows User To Enter Unknown Number Of Income / Expense Amounts

Feb 21, 2014

I'm trying to create a program that allows the user to enter an unknown number of income and expense amounts. The program has to us see a while loop and display the income total, expense total, and total profit or loss. I've got it really close, but I'm doing the loop wrong. It counts the sentinel value (-1) towards the total, instead of just ending like it is supposed to.

#include <iostream>
using namespace std;
int main() {
//declare variables
double incomeInput;
double expenseInput;
double incomeTotal=0;
double expenseTotal=0;

[code]....

View 5 Replies View Related

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 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# :: How To Write If Statement With Specific Date

Jun 2, 2014

Writing an if statement where the date has to be greater then 1/1/1880?

class Movie {
private DateTime m_ReleaseDate = DateTime.MinValue;
public DateTime ReleaseDate {
get { return m_ReleaseDate; }
set {
if (value > DateTime.FromOADate("1/1/1880")) {
m_ReleaseDate = value;
} } } }

View 1 Replies View Related

C :: Enter Date - Calculating Next Day

Mar 14, 2013

Currently I am working on a program where you enter in a date 14 03 2013 (Day, Month, Year) and you get the next day. I seem to be coming stuck with months with less than 31 days, and the whole leap year thing. Here is my code so far.

Code:
#include <stdio.h>
int day, month, year, next_day, next_month, next_year, calculation;
int main() {
printf("Enter a date in the form day/month/year: ");
scanf("%d %d %d", &day, &month, &year);

[Code] .....

View 4 Replies View Related

C :: Reading And Printing In A Specific Format Strings Of Characters And Integers

Feb 23, 2015

I have been skimming and searching but dont know how to word the search just right to find what I need to know. I have written simple stuff with the support of tutorials like weight conversion or loops counting up to a set number. Nothing amazing. The other day I found out how to input and print a string rather than a single text character which i though was bad ass. I even got it to read multiple strings on a single line and found a way to read multiple lines. I can even format it to read both integers and characters on the same line as long as I know the predefined format.

On to my question... How do I read multiple lines with both carecters and integers. for instance:

nissan 1996
toyota 1998
or more comples like
nissan gtr 1996
toyota markii 1998

I want to use
int year;
char make[10]; maybe need to use char make[10][10]; for an array i would guess.
char model[10]; optional for the extra data

but reproduce what i read in a different order. say...
1996 nissan
1998 toyota
vice the original format.

this is what I have tried.

Code: scanf("%s %s", &make,&year);

//The way I seen to read multiple lines was on here

scanf("%[^/t]", %make);

But this wont let me separate the two into two differnet definded data types. Let alone use printf to display them in reverse order.

View 1 Replies View Related

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 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 That Will Allow A User To Enter Their Name

Jul 2, 2013

I am trying to make a program that will allow a user to enter their name, from this point, three options should be present for the user to choose, then from that point, two more options should be present. I have if else statements in a switch case and I get the "undeclared" error for the a in the first " if(specificage == a) ".

NOTE: I use Code::Blocks.

Here is the code:

Code:
#include <stdio.h>
#include <string.h>
int main(){
char name[50];
char ageclass[50];
char specificage[50];

[Code] ....

View 3 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++ :: 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# :: Make User Choose A Specific Path?

May 24, 2014

I am working on a program in C# that should make a user choose a specific path for the program to work.

The path they are choosing is a path for a game and from that selected path I use coding to load pictures from to the program.

Anyhow

I am able to make the user choose a path and save the selected path in a xml file.

But the user can select ANY path.

How could I do to make the user choose a specific path that I want them to choose?

View 13 Replies View Related

C :: Program To Convert A Number Into A More Readable Format

Oct 14, 2014

I wanted to write a program to convert a number into a more readable format. It's like, if the input enters the number as 2361263 the output should be like 2,361,263. I went about this problem like extraction the number first and then if the count was equal to multiple of three i'd print ',' instead of the number.

But initially when i wrote the code for extracting a single digit from the number

Code:

#include<stdio.h>
void main() {
unsigned long long num=pow(2,50);
int count=0;
while(num!=0) {
int last_digit;

[Code]....

I know that I'd lose the number when i finish printing it, but still I only end up printing the entire number in reverse order.

As in if the input is 1234 the output is 4,321 which is not what i want.

One way of overcoming this problem is to store the values in an array and then reading then back from the end. But i wanted to know if there is a better solution than this? To extract the digits from the number in the same order as it is in the number

View 5 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++ :: Looping User Input For Specific Data Type

Apr 17, 2015

Here's my code so far:

Code:
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int dayNumber = 1;

[Code] ....

The code, when run, prompts the user to input an integer like this:

Code:

Day 1
Andy :>12
Bill :>7
Charlie :>15

Day 2
Andy :>5
Bill :>25
Charlie :>14
.
.
.
etc.

Ok, so the code prompts the user to enter an integer for each of the 3 persons and then increments the "Day" and so on... When the user enters a negative value (-1, -2, etc.), the loop is broken and the program ends. Alright, everything is hunky-dory so far. 2 things which I can't figure out.

1. when the user doesn't enter anything and just hits return, the cursor drops a line and is still awaiting an input but doesn't show the prompt "Andy :>", for example. How can I get it to repeat the last prompt when the user doesn't enter anything? Like:

Code:

Day 1
Andy :>
Andy :>
Andy :>12
Bill :>25
Charlie :>15
.
.
etc.

2. When the user enters a letter or a special character, the program blows up. How can I correct this?

I've tried changing the data type for the variable used for the input, tried using getline, get, etc. With my current beginner knowledge, I'm missing something. So how can I get this to work?

The program should allow only integers to be entered, while allowing a negative number to trigger the loop to break or the program to end, and while re-prompting the last person if the user entered an invalid input.

View 13 Replies View Related

C :: Program That Determine Day Number In A Year For A Date?

Oct 21, 2013

Write a program that determines the day number (1 to 366) in a year for a date that is provided as input data. As an example, January 1st, 1994, is day 1. December 31, 1993, is day 365. December 31, 1996 is day 366, since 1996 is a leap year. A year is a leap year if it is divisible by four, except that any year divisible by 100 is a leap year only if it is divisible by 40. Your program should accept the month, day, and year as integers. Include a function leap that returns 1 if called with a leap year, 0 otherwise. Extend the requested solution so that your program continues to prompt the user for new dates until a negative year is entered. This is what I have so far.

Code:
#include <stdio.h>
#include <stdbool.h>
int main(void) {

int d,m,y;
int days=0;
int k;

[Code] .....

I am unsure how to make this a loop so that it keeps asking for dates?

View 9 Replies View Related







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