0

Code compiles and runs correctly, just need to have the 'total' keep adding to itself after the do you want to continue question. Right now it clears it everytime after it asks that question (Hopefully that makes sense)

#include <iostream>
using namespace std;
int main()

{
	double length =0;
	char operation;
	double total = 0;
	char answer = 'Y';

do 
{
cout << "Please enter a length: ";
	cin >> length;
cout << "(I)nches, (F)eet or (M)eters? ";
	cin >> operation;

	if (operation == 'M')
		{
		total = length ;
		}

	if (operation == 'F')
		{
		total = (length / 3.2808) ;
		}

	if (operation == 'I')
		{
		total = ((length / 12) * 3.2808);
		}
	
	
	
cout << "The current total length is " << total<< " meters." << endl;
cout << " Do you want to continue (Y/N)? ";
	cin >> answer;
	
}
	while (answer == 'Y');
	cout << "Goodbye!";
}
3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Protuberance
0

put
total += length,
total += length/3.208,
total += ((length / 12) * 3.2808);

in their respective places. Note D += A is shorthand for D = D + A
Dont forget to terminate the statements.

0
do 
{
   total += total;     //there is
cout << "Please enter a length: ";
	cin >> length;
cout << "(I)nches, (F)eet or (M)eters? ";
	cin >> operation;

	if (operation == 'M')
		{
		total = length ;
		}

	if (operation == 'F')
		{
		total = (length / 3.2808) ;
		}

	if (operation == 'I')
		{
		total = ((length / 12) * 3.2808);
		}
	
	
	
cout << "The current total length is " << total<< " meters." << endl;
cout << " Do you want to continue (Y/N)? ";
	cin >> answer;
	
}
	while (answer == 'Y');
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.