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)
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....
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();
In the above program, I am calculating the square of float number. But sometimes the number is entered as NAN and sometimes Output is NAN. What is NAN? I am entering floating point number, then y NAN is entered?
I am having trouble understanding the mantissa of a floating point number. I have divided up the floating point number into the sign bit, the exponent and the mantissa, I have found the exponent, but I am not sure what to do with the mantissa? From what I have gathered so far i divide the mantissa by ten until I get a number between 1 and 10. after that i convert the number into a decimal with everything after the decimal point (or radix) being a fractional number. But when I do that on paper I dont get my intended number. How do i put the exponent and mantissa together to make a decimal from my floating point?
ex. input is 00111010000111111111011000001000 sign is 0 exponent is 01110100 which is 64+32+16+4-127=-11 mantissa is 00111111111011000001000 which would be 1.11111111011000001
When i convert that i get 1.99756622314 i dont know what to do with the -11 exponent and the answer i want is 6.1e-4
Having an issue with the following code. I read in a decimal value from a text file, use atof (or strtod, either gives the same error) to convert the read value into a floating point number. When putting the output of atof in a double, it works fine. However when putting the output of atof into a float, the decimal places get lost. Putting the result in a double, then into a float gives the same result. This only happens when using getline.
I've tried using temp arrays to put the result of pch in, sprintfs and such to try and work around it, but whenever a value originates from the getline command, the float value always loses decimal places. I've also tried varying the precision in the printf statement, but its always the same. When I write the float result to a file via FILE.write in binary mode, the result comes out without the decimal places when I read it back in later.
The simple solution is to not use float and use double, but there are a number of reasons I'm using float to begin with and don't want to change that.
Side note, this code works fine on a windows machine, the error is coming from using g++ on a mac.
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?
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
I tried to write a simple program to calculate monthly yield, APR, and principle in various directions. Anyway, here's some code to get the APR from the principle and monthly yield. When I run it though, it spits 0 at me every time! What the problem is; the other functions work just fine and the code line for the APR calculation is just what it ought to be - I see neither a math nor tech problem here.
Here is the offending function:
Code: void calculateAPR() { int principle, monthlyYield, apr; cout<<" Please input the principle:"; cin>>principle; cin.ignore();
So, I think that the above expression converts to 0x49 | 0x00 ... and the complete expression should be 0x49 for me.
But, the compiler gives me the result of 0x4949 as two bytes.How does the compiler calculate this expression as two bytes?show me the steps included in the calculation of this expression?
I want to have calculations take place inside a switch statement that calls the appropriate function. The menu portion of the program works well, but I can't figure out how to let the user actually input 2 different numbers to the functions. My questions are:
1. If I use scanf to assign values to the variables, what determines end of input to each variable? (ie.. scanf("%d%d", &a, &b) what is the end of a, what is the end of b?)
2. Should I assign the variables to user input inside the switch, or try to do it in the functions below?
3. Is there something I haven't thought to ask that will screw me over? I'm really new to this.
Code: #include<stdio.h> int add(int b, int a); int mult(int b, int a); main() {
[Code] ....
This really was a test of multilayer menu, but I want to add functionality if I can.
Changed a variable before posting and didn't change all the conditions testing it.
I tried CRC 16, 32 and with polynomial 0xEDB88320L, and with all these tries, I cannot find the correct checksum, it is my main problem.I don't want C++ code source, but I am searching for the method or algorithm to find it. If you want to know, this string in base64 contains an string compressed in zip, which contains an UTF16 XML. I want to modify information, and modify Adobe Projet (prproj)
Write a program that outputs inflation rates for two successive years and whether the inflation is increasing or decreasing. Ask the user to input the current price of an item and its price one year and two years ago.
To calculate the inflation rate for a year, Uh, no, that’s wrong! To calculate the inflation rate for a year, subtract the price of the item ONE YEAR AGO from the price of the item for that year and then divide the result by the price a year ago. For example: 2014-Inflation-Rate = (2014-Price minus 2013-Price) / 2013-Price.
Your program must contain at least the following functions:
•a function to get the input •a function to calculate the results •a function to output the results
I am trying to calculate a CRC of a Base64 string. I know the answer of the checksum, but I don't how to calculate it (It is for Adobe project).
I give you the correct checksum : 2942042514
And now the string : AQAAAAAAAABsYAAAAAAAAENvbXByZXNzZWRUaXRsZQB4nO0d2XIaSbI+hZ13 m0NCR0QNE7KOHcXKlkMwtnhyIIRkdjGwgGxpP35386jqursRsk0zQygkd+dR lVmVmZVdl//3Xyl+E4/iixiJivgqBmIm5mIoJmIsfhW/iLp4LWrwbwUwY9EH +C1gx+KesH+IjjgTr4Bqj2h+Ey0hxRHQTMQNcHwSV/A0EYsA3oFSFlDngDAf
[Code] ....
I tried CRC 16, 32 and with polynomial 0xEDB88320L, and with all these tries, I cannot find the correct checksum, it is my main problem.
As you see, I have taken input from the user just after calculating the whole palindromes. So cant we calculate this at compile time? because runtime of this program is extremely slow.
Another qs. I first tried to use array but It didnt allow 2*10^9 sized array. so what should I do whenever I need that size of array?
I am basically trying to make a program for a calculator. I am struggling with how to do the sine calculation. this calculation will take place at line 158.
#include <iostream> #include <cmath> using namespace std; int main() {
I'm working on a payroll program and I'm having problems that are causing calculation errors.
My input file is 1234FredJones4025.00 2345 TerrySmith6010.00
The errors I get are from the regular pay, over time pay, gross pay, tax amount and net pay calculations. They all look similar to this (6e+002). I believe they are occurring because regular pay isn't calculating correctly and the rest depend on that for their calculations. However, I can't see why regular pay isn't calculating correctly.
#include <fstream> #include <iostream> #include <iomanip> using namespace std; class payroll{ ifstream fin; char employeeid[100];
// DEBUG3-4 // This program contains a class for a cylinder // Data members are radius and height // The volume is calculated as pi times radius squared times height // If no height is given, it's not a cylinder - it's a circle!
#include<iostream> using namespace std; //declaration section
I have a doubly linked list, which reads in a set of coordinates x and y.
I need to pass these coordinates into a method called calculateImportance and execute Pythagoras on them. With this in mind I need to be able to access the pointers current, next and prev.
The issue I am having, is that I am unable to pass the pointers through to the method?
This is the list.h
#include <iostream> class List { private: typedef struct node { int xCoord; int yCoord; float importanceFactor;
I am trying to work on a C++ program to calculate the quadratic formula using input files and classes. I have written my class, but I am trying to find a way to take an input file with unknown number of lines of coefficients. How do I take each integer from each line and set that value as "a" and "b" and so forth, then start over on the next line?
This is what i have so far.
fstream inputfile;//users input quadratic coefficients file ofstream outputfile;// outputs a file with solutions int main(int argc, char *argv[])// argc is argument count, char *argv[] is array of array of characters for arguments { string dataline; getline(inputfile, dataline);