Division calculator

Am having some trouble with a division calculator

here are the errors

1>c:\documents and settings\timbo\my documents\visual studio 2008\projects\new calculator\new calculator\main.cpp(59) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
1>c:\documents and settings\timbo\my documents\visual studio 2008\projects\new calculator\new calculator\main.cpp(62) : error C2653: 'TIMSPrompt' : is not a class or namespace name
1>c:\documents and settings\timbo\my documents\visual studio 2008\projects\new calculator\new calculator\main.cpp(63) : warning C4244: 'return' : conversion from 'float' to 'int', possible loss of data
1>Build log was saved at "file://c:\Documents and Settings\Timbo\My Documents\Visual Studio 2008\Projects\New Calculator\New Calculator\Debug\BuildLog.htm"


here is my code

main.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>

#include "PromptModule.h"
#include "ErrorHandlingModule.h"

using namespace std;

float GetDividend(void) // returns divedend, a float
{
	float Dividend = 0;

	cout << "Number to be divided: ";
	cin >> Dividend;

	return Dividend; // returns a copy of Dividend
}

float GetDivisor(void) // returns the divisor
{
	float Divisor = 1;

	cout << "Divisor: ";
	cin >> Divisor;

	return Divisor;
}

float Divide
(const float theDividend,const float theDivisor) // takes unmodifiable (const) arguements, returns float
{
	return (theDividend/theDivisor); // returns the result
}



void PauseForUserAcknowledgement(void)
{
	// note : You must type something before the enter key
	char StopCharacter;
	cout << endl << "Press the \"1\" key and \"Enter\": ";
	cin >> StopCharacter;
}

int main(int argc, char* argv[])
{
	TIMSErrorHandling::Initialize();

	float ReturnCode = 0;

	try
	{
		float Dividend = GetDividend();
		float Divisor = GetDivisor();

		cout << Divide(Dividend,Divisor) << endl;
	}
	catch (...)
	{
		ReturnCode = TIMSErrorHandling::HandleNotANumberError();
	};

	TIMSPrompt::PauseForUserAcknowledgement();
	return ReturnCode;
}
The warnings are happening because your error handling routines are returning integers, but you are storing them in a float (ReturnCode).

The error is because the PauseForUserAcknowledgement() function is not part of the TIMSPrompt class. Line 36 should be:
 
void TIMSPrompt::PauseForUserAcknowledgement(void)


This is assuming you defined that method in the TIMSPrompt class in your header file.
Why exactly did you add this? TIMSPrompt::

And another question: What would you do if you had to input addends, multiplicands, bases, exponents, etc. Would you write a function for each of them?
Topic archived. No new replies allowed.