help i am a beginner and i need help with my final program.
i beleive i have everything set but i am not sure how to write the function.
i want the function to add up all of the rides and give a grand total but i can not get it to add all the hides.

]//christine gershen
//taxi cab ride
// Midterm
#include <iostream> // required to perform C++ stream I/O
#include <string> //requied to perform string varibles
#include <iomanip> //requied to perform parameterized stream manipulators

using namespace std; // for accessing C++ Standard Library members

double calculate ( double change);
double total; //storge the total rides

int main() //requied for every program;should return integer result code
{
		int length; //storge the length of the ride
		double first; // storges total for only on ride
		char response='y'; //storge for response of another ride

	

	while (response!='n' && response!='N')
	{ 
		cout<<"Please enter the length of the trip:";
		cin>>length;
		
		if (length<0)

			{
				cout<<"Please enter a length greater than -1:"<<endl<<endl;
			}
		else
			if (first = length * 1.85 + 2.50)
			{
				cout<< "$" << first << fixed << setprecision(2)<<endl<<endl;
			}
		
	cout<<"would you like to take another trip (y = yes, n = no)?";
	cin>>response;// output response
	cout<<endl;//add space to make easier to read

	} //end while

	calculate(length);
	if (response='n')

	{
		cout<< "Total: $" << total << fixed << setprecision(2)<<endl<<endl;
	}

	

	





   return 0; // indicate that program ended successfully

} // end function main

	double calculate ( double change)
	{

		return change * 1.85 + 2.50;
		change=+total;
	}

You need to change your expression statements in your flow of control.

if (first = length * 1.85 + 2.50) // will always be true

if (response='n') // will always be true


You also don't assign total to anything. At no point in your program do you have written

total =              // this partial statement is not in the program, how can you output the total if you haven't equated it to anything.

Be careful of your math. This expression change * 1.85 + 2.50 will be interpreted as (change * 1.85) + 2.50. If you intended this change * (1.85 + 2.50) then that is NOT what you will get. So, make sure to properly bracket your math expressions, or you may not get the results you intended, and the satellite you launch may end up in the ocean instead of orbit... :-)

Also, you are not setting 'total' in your calculate() function. If you want to add the change to 'total' and return that, then this would be more appropriate, assuming the math is what you intended.

double calculate( double change )
{
   change = (change * 1.85) + 2.50;
   return total += change;
}
double calculate ( double change)
	{

		return change * 1.85 + 2.50;
		change=+total;
	}

In the previous code,

change =+ total;

is never ran. There is a return statement just prior to that statement that will forever skip change =+ total.

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.