GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 14-Aug-2004, 21:15
crystalattice's Avatar
crystalattice crystalattice is offline
Flame War Instigator
 
Join Date: Apr 2004
Location: San Diego
Posts: 1,576
crystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nice

Wierd errors (again)


I'm getting errors on this one also, but these ones don't make sense.

"Syntax error before 'double'" received on the definition of gregToJul() but there's nothing before it except for comments.

"'D' undeclared" in the body of the gregToJul() definition. I've never had this problem w/ a function definition before; if I take an argument and rename it for the body of the function, it usually counts as declaring it, right? Also, I don't get an error when I change the argument "month" to "M" but I do here ("day" to "D"). However, within the actual julian date conversion formula, I do get an 'M' undeclared error but not the others.

Finally, I get two warnings regarding getting an 'int' from 'double' when I return the julian date, but I never refer to int values.

Any ideas or suggestions?
Thanks.

CPP / C++ / C Code:
/************************************
*Purpose:  Generate a non-graphical biorhythm.
*************************************/

#include <iostream>
#include <cmath>
#include <cassert>

#define PHYS 23	//days in the physical cycle
#define EMOT 28	//days in the emotional cycle
#define MENTAL 33	//days in the mental cycle

using namespace std;

//Input conversion functions
double gregToJul(double birth_month, double birth_date, double birth_year);
double gregToJul(double check_month, double check_date, double check_year);

//Output and calculation function
void biorhythm(double days_lived, int& phys, int& iq, int& emotion);

int main()
{
	int phys, iq, emotion;
	char y, n;
	
	cout << "Enter your the month (number) you were born: ";
	int birth_month;
	cin >> birth_month;
	
	cout << "\nEnter the day you were born: ";
	int birth_day;
	cin >> birth_day;
	
	cout << "\nEnter the year you were born: ";
	int birth_year;
	cin >> birth_year;
	
	//this function call converts the "normal" birthday into the Julian date
	double jul_birth_date=gregToJul(birth_month, birth_day, birth_year);
	
	//loop for selecting the date user interested in
	do{
		cout << "\nEnter the month (number) you want to check: ";
		int check_month;
		cin >> check_month;
	
		cout << "\nEnter the day you want to check: ";
		int check_day;
		cin >> check_day;
	
		cout << "\nEnter the year you want to check: ";
		int check_year;
		cin >> check_year;
		
		//this function call converts the user's day of choice into Julian
		double jul_check_date=gregToJul(check_month, check_day, check_year);
		
		//determine how many days lived
		double days_lived=jul_check_date-jul_birth_date;
		
		biorhythm(days_lived, phys, iq, emotion);
		
		cout << "\nDo you want to check another date? y or n: ";
		char recheck;
		cin >> recheck;
	while (recheck==y);
	
	cout << "\nYour current physical index is: " << phys
		<< "\nYour current intellectual index is: " << iq
		<< "\nYour current emotional index is: " << emotion
		<< "\nYour biorhythm index is: " << phys+iq+emotion;
}

/**********************************************
*gregToJul() converts the Gregorian birth date into Julian version.
*
*Receive:	month, an (integer) number
*			day, an (integer) number
*			year, an (integer) number
*Precondition: the date is valid
*Return: 	JD, a (real) number
************************************************/

double gregToJul(double M, double D, double Y)
{
	assert (1<=M<=12);
	assert (1<=D<=31);
	assert (1801<=Y<=2009);
	
	//this formula is modified from the US Naval Observatory function;
	//the GMT conversion factor has been removed for clarity
	double JD = 367*Y-(7*(Y+(M+9)/12))/4 + (275*M)/9 + D + 1721013.5;
	return JD;
}

/**************************************************
*biorhythm() takes a person's age and returns the physical, 
*intellectual, and emotional cycle indexes.
*
*Receive: 	days_lived, a (real) value
*Send back: phys, an (integer) value
*			iq, an (integer) value
*			emotion, an (integer) value
************************************************/

void biorhythm(double days, int& phys, int& iq, int& emotion)
{
	phys=days/PHYS;
	iq=days/MENTAL;
	emotion=days/EMOT;
}
__________________
Start Programming with Python-A beginner's guide to programming and the Python language.
-------------
Common Sense v2.0-Striving to make the world a little bit smarter.
  #2  
Old 14-Aug-2004, 23:07
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,791
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
For starters, you are missing the } in your
CPP / C++ / C Code:
do {
}while

Put it there, then you can get on with it.

Good luck!

Dave
  #3  
Old 15-Aug-2004, 21:00
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,258
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
I don't get any of the errros you do. Only the one Dave caught and one other.
__________________

Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough.
-- Pearl Williams
  #4  
Old 15-Aug-2004, 21:02
crystalattice's Avatar
crystalattice crystalattice is offline
Flame War Instigator
 
Join Date: Apr 2004
Location: San Diego
Posts: 1,576
crystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nice
That, plus a few other things I found, fixed it. Thanks!
__________________
Start Programming with Python-A beginner's guide to programming and the Python language.
-------------
Common Sense v2.0-Striving to make the world a little bit smarter.
 
 

Recent GIDBlogToyota - 2008 November Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't figure out errors crystalattice C++ Forum 3 17-Jul-2004 08:58
there are some errors but where?? small_ticket C Programming Language 6 18-May-2004 14:10
Error C2143: syntax error : missing ';' before 'type' small_ticket C Programming Language 6 15-May-2004 12:59
Can somebody look at this and point out any errors to me soulfly C Programming Language 7 31-Mar-2004 10:45
Rambus 128mb Pc800 memory errors momo Computer Hardware Forum 1 11-Mar-2004 05:22

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 03:19.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.