C++ I couldn't write output,, I dont know how to do,, please need help.... :(((?

closed account (9N7koG1T)
Prompt the user to enter a date in the YYYYMMDD format. Example: 10 March 2010 is 20100310.

Read the user input into a variable.

Print an error message and exit the program if the user enters a negative number.

Split the YYYYMMDD number into its respective YYYY, MM, DD pieces using integer division and the modulus operator. [hint: 20100101 / 10000 = 2010 and 20100101 % 10000 = 101]

Print a line that has the following format.
YYYYMMDD is MM/DD/YYYY

examples...

20100314 is 3/14/2010
19571105 is 11/5/1957
20380118 is 1/18/2038

Your source code file must contain a file comment block. In addition, you need to turn in a printed copy of the output generated by your program for at least three different inputs.

This is my assignment and my question is same thing that was last week.. I couldn't type printed copy of my output..?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
 using namespace std;

 int main()
 {
 int currentdate, day, month, year;

 cout << "Please enter a date in YYYYMMDD format (Example: 10 March 2010 is 20100310): ";
 cin >> currentdate;

 day = currentdate % 100; // getting date
 month = ( currentdate / 100 ) % 100; // Month
 year = ( currentdate / 10000 ); // getting year

 if ( currentdate < 0 || day < 0 || month < 0 || year < 0 )
 {
 cout << "***Error...Please enter positive numbers" << endl;
 exit(1);
 return 0;
 }

 cout << currentdate << " is " << month <<" / " << day <<" / " << year <<endl;



 system("pause");

 return 0;
 }

I couldnt type thıs part...
Your source code file must contain a file comment block. [b]In addition, you need to turn in a printed copy of the output generated by your program for at least three different inputs.
Last edited on
A file comment block is probably meaning a large comment at the top of the file that describes the file, gives the author's name, etc. The output just means your professor also wants you to run your program and input several different numbers and include them with your program as examples.
closed account (9N7koG1T)
Like that?? Do you think is missing anything?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*************************************************************
    Programmer:   X.x.xx.xx.X:xX:
    Assignment:   YYYYMMDD
    Description:  YYYYMMDD format converts MM / DD / YYYY
*************************************************************/
#include <iostream>
using namespace std;

int main()
{
	int currentdate, day, month, year;

	cout << "Please enter a date in YYYYMMDD format (Example: 10 March 2010 is 20100310): "<<endl;
	cin >> currentdate;

	day = currentdate % 100;        // getting date
	month = ( currentdate / 100 ) % 100;        // Month
	year = ( currentdate / 10000 );       // getting year

	// for negative numbers
    if ( currentdate < 0 || day < 0 || month < 0 || year < 0 )
	{
		cout << "***Error...Please enter positive numbers" << endl;
		exit(1);
		return 0;
	}

	cout << currentdate << " is " << month <<" / " << day <<" / " << year <<endl;
	cout <<"examples..."<<endl;
	
	cout << " 19920803 is 8 / 3 / 1992 "<<endl;
	cout << " 20120304 is 3 / 4 / 2012 "<<endl;
	cout << " 20110726 is 7 / 26 / 2011"<<endl;
	
	
	
	
	
	system("pause");

	return 0;
}
Your file comment block looks fine to me, though you may want to check any guidelines you professor has given for what it needs to contain.

As for your output, you don't need to include it in the code itself; I'd just have a separate text file with the output in it to be turned in with your assignment. Again, you professor probably has some guidelines as to what exactly they want. I'd expect they basically want you to show the entire program output for inputting three different numbers.
closed account (9N7koG1T)
I haven't tried before to add the outputs into my code. Hopefully, I will work, Do you have any idea or method for adding outputs? if so can you type?
Run your program.
$ ./a.out >> output_file
That's stream redirection, it's sending stdout to a file, appending the output.

Edit: you'll probably want to see the output that you are sending
$ ./a.out | tee --append output_file
Last edited on
Topic archived. No new replies allowed.