Please help

closed account (2A7X92yv)
I did this much but i am getting this error message - 1>c:\users\boaz george\documents\visual studio 2010\projects\program 9\program 9\program 9.cpp(46): warning C4244: '=' : conversion from 'double' to 'int', possible loss of data


Also i am stuck at this question how do i do the rest please need ur help :
. Use a function to read in the numbers involved. These numbers will be doubles. Also write a function that reads in the operator and returns a boolean – true if the operator is valid, false if not valid. This function will have two parameters. First is a string of characters containing the valid operators. The second is a reference parameter where the operator will be placed if the operator entered is valid.

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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <iostream>

using namespace std;

#include <stdlib.h>

void readInt(double*number1) { 
       cout << "Please enter a number and press ENTER: ";
       cin >> *number1;
}

double add(double number1, double number2) { return number1 + number2; }
double subtract(double number1, double number2) { return number1 - number2; }
double multiply(double number1, double number2) { return number1 * number2; }
double divide(double number1, double number2) { return number1 / number2; }
void main ()

{
bool	IsOpValid;
double number1;
double number2;
int	answer;
char	Op;
	


s:
number1 = 0;
number2 = 0;
answer = 0;



do	{
p:
readInt(&number1);
cout << "Please enter an operator, 'c' to clear, or 'x' to turn off and press ENTER: ";
cin >> Op;
IsOpValid = false;

double *readInt(&number2);

switch (Op)
{
case '+':
answer = add(number1, number2);
break;
case '-': 
answer = subtract(number1, number2);
break;
case '*': 
answer = multiply(number1,number2);
break;
case '/': 
if (number2 == 0) {
cout << "Cannot divide by 0" << endl;
continue;
} else {
answer = divide(number1,number2);
}
break;
case 'c':
case 'C':
cout << "Clearing Calculator." << endl;
continue;
case 'x':
case 'X':
IsOpValid = true;
cout << "Turning Off Calculator." << endl;
exit (0);
break;
default:
IsOpValid = true;
cout << "You have entered an invalid operator." << endl;
cout << "Please enter +, -, *, /, 'c' or 'x' as operator. " << endl;
break;
}

cout << "The result is: " << answer << endl;

} while (!IsOpValid);





}
It's not an error, it's a warning. You're function returns a double value but you're storing it in an integer called 'answer'. This will truncate anything after the decimal point.

For example:

1.7 + 1.2 = 2.9.

Storing that result in an integer will give you a result of 2.
closed account (2A7X92yv)
But why can't I build this in visual studio? It gives me build failed.... Also how do I do this portion ... Also i am stuck at this question how do i do the rest please need ur help :
. Use a function to read in the numbers involved. These numbers will be doubles. Also write a function that reads in the operator and returns a boolean – true if the operator is valid, false if not valid. This function will have two parameters. First is a string of characters containing the valid operators. The second is a reference parameter where the operator will be placed if the operator entered is valid. Pleaseeeeeeeee help me
Topic archived. No new replies allowed.