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


ADVERTISEMENT

C/C++ :: Output Number Of The Day Based On Month Day And Year - Check Leap Year

Feb 14, 2015

Whenever I run the program I get no errors yet it doesn't return a value for total it just exits the program. The program is supposed to output the number of the day based on the month day and year and check whether it is a leap year.

#include <iostream>
using namespace std;
int totaldays();
int days();
int month, day, year;
bool leap();
int main() {
char dash;
cout << "Enter the date in mm-dd-yyyy format to find out what day this is in the year." << endl;

[Code] ....

View 2 Replies View Related

C++ :: Date Class - List Major Holidays And Print Calendar For Given Year

Mar 20, 2013

I'm trying to implement a Date class to create a simple application for " Major U.S. holidays calendar System ", that provides a list of major holidays for a given year AND prints the calendar for the given year either online or write to a file. I need to finish up the class date.h, which is

#ifndef DATE_H
#define DATE_H
#include <string>
#include <iostream>
using namespace std;
string Month[]={"" , "January", "Febraury", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December"};

[Code] .....

View 1 Replies View Related

C++ :: Read Date From File To Determine Different Days?

Mar 22, 2014

How do I read a date from a file to determine different of days

For example my date.txt contains:

1 23/01/2012 05/02/2012

Currently my code is:

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

[Code].....

View 14 Replies View Related

C/C++ :: Read Date From File To Determine Different Days

Mar 21, 2014

How do I read a date from a file to determine different of days

For example my date.txt contains:

1 23/01/2012 05/02/2012

Currently my code is:

#include<iostream>
#include<fstream>
using namespace std;
class Date {
public:
int day;
int month;
int year;
int total_day;
Date();

[Code] ....

View 1 Replies View Related

C++ :: Program To Determine Number Of Inputted Riders And Closes When Input Is -1?

Jan 16, 2015

I seem to be having a logical error but can not find the sources.

#include <iostream>
using namespace std;
int main() {
int student = 0;
int adult = 0;

[Code] ....

View 1 Replies View Related

C++ :: Read User Input To Determine Different Discounts By Number Of Units Sold - Errors In Program

Jun 23, 2014

it will not run and im not sure why. I have a couple of errors, but I'm not sure why.

Here is my code.

//Reads input from user to determine different discounts by number of units sold

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

int main() {
//Declaration and Initialization of variables
int quantity;
double discount,price = 99.00,totalCost;

[Code] ....

View 1 Replies View Related

C/C++ :: Compare Time Fetched From Two Week Number Of Different Year?

Jul 5, 2012

How to compare the time fetched from two week number of different year using C,C++.

I have used a naming convention for the files generated in a linux system. The naming convention will have the week number and date's day indication like Monday means M. I need to compare the two files of same week but on different years and calculate the time?

View 1 Replies View Related

C/C++ :: Day Of The Year Program

Nov 5, 2014

I have this project, The problem is I have most of the code written, I am just having trouble setting it up correctly and placing it correctly. My code is rather long but as I said I know this is the longer and harder way to go about this.

//This program will be used to find out the day of the year
#include <iostream>
int month, day, year;
bool isALeapYear(int year) {
//Check if the year is divisible by 4 or is divisible by 400

[Code].....

View 14 Replies View Related

C++ :: Program To Generate Calendar For A Year

Oct 15, 2013

Problem: Write a program to generate a calendar for a year. The program should accept the year and the day of the week for January 1 of that year (0 = Sunday, 1 = Monday, etc.). The calendar should be printed in the following form:

January
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
February
1 2 3 4 5

I have wrote code that has three functions, one to print the month, one to print the days in month, and one to find if it is a leap year or not. I have gotten up to the point where I can print the 12 months with a for loop, but how to print out the days in the format above.

This is my code.

#include <iostream>
using namespace std;
void printOneMonth(int month, int& dow, int year);
void daysInMonth(int month, int year, int& dim);
bool isLeapYear(int year);
int main(){
int year=0, dow, count;

[Code]...

View 1 Replies View Related

C++ :: Program To Check The Leap Year

Oct 7, 2013

Check the Leap Year Program In C++:

#include <iostream>
using namespace std;
int main() {
int yr;
cout << "Enter year : ";

[Code] ....

Check the LeaP Year... [URL] ....

View 2 Replies View Related

C :: Program To Calculate Business Days In A Year

Nov 11, 2014

I need to make a program to calculate the business days (Monday-Friday) in a year in C. As example:

Input
2026
Output
261

I need to consider that the year could be a leap year and that every year can start with a different day. My Problem is that i dont know how to implement the right number of business days in C. I wrote down the business days in Excel for 2010-2040. I cant see any system behind it, some years have 261 business days, some have 260 or 262 but in no order.

View 7 Replies View Related

C :: Program To Show Highest Negative And Lowest Positive Temperature Of Year

Jan 19, 2014

I have an assigment and I don't know yet how to write this program :" I introduce the average monthly temperatures of a year(12 values for 12 months). When I compile the program it needs to show the highest negative temparature and the lowest positive temperature of that year.

Example: Entry data: -4 -6 0 5 10 20 24 25 17 8 -1 -7 exit data : max negative= -1 and min positive= 5 "

View 11 Replies View Related

C :: Determine Minimum Number Of Changes That Can Be Made

Mar 7, 2013

You are given an integer, perhaps a very long long integer, composed of only the digits 1 and/or 2. You have the ability to change a 1 digit into a 2 and a 2 digit into a 1 and must determine the min. number of changes that you can make resulting in no 2 digits remaining in the number that are in a position(in terms of powers of ten) higher than any 1 digit.

example:

2222212 number of changes:1
1111121 1
2211221 3
1122112 2

no negative numbers.

how to get started. Also I'm not allowed to use anything related to arrays or sorting.

View 6 Replies View Related

C/C++ :: Determine Smallest Number Xmin

Jan 21, 2014

In a fashion similar to that in Fig. 3.11(shown below), write a short program to determine the smallest number, xmin, used on the computer you will be employing along with this book. Note that your computer will be unable to reliably distinguish between zero and a quantity that is smaller than this number.

fig311.png

View 2 Replies View Related

C :: Determine Number Of Binary Palindromes In Given Range?

Oct 26, 2013

Write a program to determine the number of binary palindromes in a given range [a;b]. A binary palindrome is a number whose binary representation is reading the same in either forward or reverse direction (leading zeros not accounted for). Example: the decimal number 5 (binary 101) is palindromic.

View 2 Replies View Related

C :: Calculation Birth Date As Floating Number

Sep 25, 2014

i want to calculate age of a person so then i try to make an algorithm which is used in a function like (i know to use math.h for abs()) double age_calculator( int year, int month, int day);

Code:

double age_calculator( int year, int month, int day);
// p means present(current)
int pyear=(2014-year)*365;
int pmonth=(abs(9-month))*30;
int pday=abs(25-day);
return (pyear+pmonth+pday)/365.0;

how can i use current date, i mean i want to use date of present day instead of 2014,25 and 9. I don't know how i can use date of every day.For instance my function returns 14.74 for the parameters; 2000, 01, 01 (for the current day 25/09/2014)

View 6 Replies View Related

C++ :: Determine Number Of Times Change Each Specific Character In String To Make It Palindrome

Feb 19, 2015

I'm trying to determine the number of times I have to change each specific character in a string to make it a palindrome. You can only change a character one at a time from the end.

Example: "abc" -> "abb" -> "aba" should print 2. "aba" will print 0 because it's already a palindrome. "abcd" -> "abcc" -> "abcb" -> "abca" -> "abba" will print 4 because it took 4 changes to make a palindrome.

I'm not too sure how to approach this - I figured out the case where if it's a palindrome (if reversed string is the same) then it'll print out a 0.

int main() {
int number;
cin >> number; //expecting a number for first line user input
for (int i = 0; i < number; i++) {
string str;

[Code] ....

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++ :: Program That Outputs Calendar For That Month When Given Month And Year

Mar 17, 2013

i am beginner in c++ , i need to write a programm that out ouputs a calender for a month when given a month and year using this frame work :

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
using namespace std;

[code].....

View 8 Replies View Related

C++ :: Program To Determine Coin Change

Oct 20, 2013

I have a current assignment for C++ involving us to make a program to determine coin change for example if you input the number 127 you would need 2 half dollars 1quarter and 2 pennies I have no way how to program this.

This is my code that doesn't do what i want it to

#include <iostream>
using namespace std;
int main ( ) {
float change;
int half_dollars, quarters, dimes, nickels, pennies; // declare variables

[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 Stumbling Blocks - Determine Size Of Rows To Create In Program

Apr 18, 2014

Working on an assignment and I've hit TWO stumbling blocks. I now have to take the first line from a .txt file and use that number to determine the size of rows to create in my program. I am using fscanf but the program hangs. How can I read in this number, store it and use it in a for loop?

The second issue is after reading this number I have to print each number in the .txt file under a different column. (Note that it skips a line after reading the row count.) The .txt file is set up as follows:

9 1 3 6 4 7 8 8 6 1

The output should look sort of like:

Number ​1 3 6 4 7 8 8 6 1

Here's my attempt:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <math.h>

typedef struct{
int number;

[Code] .......

View 2 Replies View Related

C++ :: Program To Determine Slope Of A Line - Stuck On Commas When Entering Numbers

Jan 1, 2013

The program I have is from a tutorial where the user enters two points on a line, and then the program calculates the mid-point and slope.

I want to modify it from it's initial form so that co-ordinates can be input in (x,y) fashion. Right now the user has to enter the x-coordinate, enter a space, and then enter the y-coordinate (lame...)

I saw people using SStream and using that to either write functions to ignore the comma or similar things for converting one file into an array, but not quite what I am trying here.

// program to determine slope of a line

#include <ios>
#include <iostream>
#include <istream>
#include <limits>

using namespace std;
void myflush ( istream& in ) {

[Code] .....

View 2 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

Visual C++ :: Program That Reformat And Output Date

May 30, 2013

Write a well-commented C++ program that reformats and outputs the date. Prompt the user to input the date in the format dd/mm/yyyy and outputs it in this format month, dd, yyyy. For example, 07/06/2012 is displayed as June 07, 2012. You are provided with the file months.txt containing the months and their corresponding numbers, for example 01January 02February etc. Use getline(monthsFile,monthString) to read in a string from the file, and use the monthString.find() function to search for the number and extract the corresponding month.

-confused by the way she told me to use getline(monthsFile,monthString) => if I just do it like this I only get the first line from the txt file (01January)
-if I try putting all the months on one line in the txt file (which i'm not even sure i'm allowed to do), I'm not sure what to do for the length of my substring output. if I make it long enough to fit longer months like September, someone entering may gets both may and june in the output
-if I input all the months into separate variables, I'm not sure how to make it only output the month entered by the user

the months.txt file is as follows:

01January
02February
03March
04April
05May
06June
07July
08August
09September
10October
11Novmber
12December

View 1 Replies View Related







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