Can someone help me please?

I have to do this turkey project, everything is working ok, exept for my oven time.
when it prints this line:

cout << "Put the turkey in the oven on the " << startThawDay + howLongToThaw <<"th " << " at " << ovenTime <<" o`clock." << endl;

the ovenTime is never right, I can`t find out where it`s wrong.

this is the whole code

#include<iostream>
#include<iomanip>
#include<string>

using std::setprecision;


using std::cout;
using std::cin;
using std::endl;
using std::fixed;
using std::string;
double turkey();
int sweetPotatoes();
int pies();
//int thanksgivingTime(int turkeyTotalDays);


int main()
{
	//int turkeyTotalDays;
	cout << "This program will help you get your food ready thanksgiving dinner on time. " << endl << endl;
	turkey();
	sweetPotatoes();
	pies();
	cout << "Your dinner will be all ready at 2pm on thanksgiving day if you follow these instructions.";
	cout << endl << endl << "Happy Thanksgiving!" << endl;
	//thanksgivingTime(turkeyTotalDays);

	return 0;
}

double turkey()
{
	int day = 26;
	int hour = 14;
	int min = 00;
	double weightOfTurkey;
	int thawTime;
	int cookTime;
	int turkeyTotal;
	int turkeyTotalDays;
	int turkeyHour;
	int startThawDay;
	int howLongToThaw;
	int ovenTime;
	string standardTime;
	string am = "am";
	string pm = "pm";

	cout << "Enter the weight of you turkey in lbs: ";
	cin >> weightOfTurkey;
	thawTime = weightOfTurkey * 6;
	cookTime = (weightOfTurkey / 3) * .75;
	turkeyTotal = (((thawTime + cookTime)* 60)+20)/60;
	turkeyTotalDays = turkeyTotal / 24;
	turkeyHour = turkeyTotal % 24;
	startThawDay = day - turkeyTotalDays;
	hour = hour - turkeyHour;
	howLongToThaw = thawTime / 24; 
	ovenTime = hour - cookTime;
	
		ovenTime = (ovenTime == 0 || ovenTime == 12)?12 : ovenTime %12;
		standardTime = (hour < 12) ?am : pm;
		hour = (hour ==0 || hour == 12)?12 : hour %12;
		
		if (turkeyHour > 0)
		{
			if( turkeyTotalDays > 1 )
			{
				cout << "It will take " << turkeyTotalDays << " days, and " << turkeyHour
					<< " hours for the turkey to be ready." << endl;
			}
			else if (turkeyTotalDays == 0)
				cout << "It will take " << turkeyHour << " hours for the turkey to be ready." << endl;
			else 
				cout << "It will take " << turkeyTotalDays << " day, and " << turkeyHour
					<< " hours for the turkey to be ready." << endl;


	cout << "Start thawing the turkey on the " << startThawDay <<"th at "<< hour << 
		standardTime << "." << endl;
	
		}
			if (turkeyHour == 0)
		{
			if( turkeyTotalDays > 1 )
			{
				cout << "It will take " << turkeyTotalDays << " days." << endl;
			}
			else
				cout << "It will take " << turkeyTotalDays << " day." << endl;

	cout << "Start thawing the turkey on the " << startThawDay <<"th at 2pm."<<endl;
	
		}
			cout << "Put the turkey in the oven on the " << startThawDay + howLongToThaw
				<<"th " << " at " << ovenTime <<" o`clock." << endl;
				

		return 0;
}

int sweetPotatoes()
{
	int totalPotatoeTime;
	totalPotatoeTime = 10 + 30;
	cout << "The sweet potatoes take " << totalPotatoeTime << " minutes to be ready." << endl;
	cout << "Put the sweet potatoes in the oven at 1:20pm on thanksgiving day.";
	cout << endl;

	return 0;
}

int pies()
{
	cout << "Put the apple pie in the oven at 1:00pm, and the pumpking pie " <<
		"at 1:15pm on thanksgiving day." << endl;
	
	return 0;
}

thanks

Recommended Answers

All 7 Replies

please explain your logic about your ovenTime. What is needed to done?

you have some "rounding problems" because C++ uses integer math, not regular math, when dividing an int into an int and then assigning that value to an int (see calculatin of cooktime which is subsequently used for calculation of oventime). Whether that's enough to cause your error I don't know as I haven't run the numbers.

dinner is supposed to be at 2pm, that`s why int hour =14, oven time is the time the turkey should go in the oven, so i`m trying to get the dinner time which is 14(hour) and subtract the cookTime from it, which is the amount of time it`s gonna take to cook, I thought that would give me the right time to put the turkey in the oven, but I did all the mall on the calculator, and everything is right, exept the ovenTime, it`s giving me crazy numbers, depending on the size of the turkey it even gives me a negative number

You calculator probably doesn't use integer math. Try changing datatypes of cooktime to double or float, rounding where appropriate, and see what happens.

I changed it to double, I tried using the weight as 10lb, and it gave me an ovenTime of -2

is my hour initialized correctly? because I now changed ovenTime = hour - cookTime; to ovenTime = 14 - cookTime; and it works fine

is my hour initialized correctly? because I now changed ovenTime = hour - cookTime; to ovenTime = 14 - cookTime; and it works fine

Because the value of the hour has been changed here:

hour = hour - turkeyHour; //<<-----
howLongToThaw = thawTime / 24;
 ovenTime = hour - cookTime;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.