Convert to double help!

Hey guys. This is my second post here to the forums!. I want some help on my second project also. Its a Calculator. The operations are working fine but i have problem on error checking. On the project it says this
"Your program should be able to handle any user input. In case the user input is
wrong you should print an error message before displaying the menu again. If you
read in a real number you MUST read this in as a string (getline(cin, strTmp)). Then
you must verify that this is a real before casting it into a real datatype.
5."

I didn't quite get the point of this. I think its supposed to read that number and if there is any letter in the string convert it to double. Maybe its that i am kinda confused. Can some 1 help me? I will post my code here
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
double addition(double&,double&,int&);
double subtraction(double&,double&,int&);
double multiplication(double&,double&,int&);
double division(double&,double&,int&);
double sumsquared(double&,double&,int&);
void lessthanrelation(double&,double&,int&);
void greaterthanrelation(double&,double&,int&);
double clearsum(double&);
double quit(int&,int&,char);
void convdouble(int&);
int main()
{
	int arithmetic=0;
	int relational=0;	
	double value,sum=0;
	char operation;
	char cont='y';
	while(cont='y')
	{
cout<<"+: Addition"<<endl;
cout<<"-: Subtraction"<<endl;
cout<<"*: multiplication"<<endl;
cout<<"/: division"<<endl;
cout<<"^: sum squared"<<endl;
cout<<"< : less than relation"<<endl;
cout<<">: greater than relation"<<endl;
cout<<"c: clear sum"<<endl;
cout<<"q: quit"<<endl;
cout<<"Enter operation:"<<endl;
cin>>operation;
switch(operation)
	{
	case '+':
		cout<<addition(value,sum,arithmetic)<<endl;
		break;
	case '-':
		cout<<subtraction(value,sum,arithmetic)<<endl;
		break;
	case '*':
		cout<<multiplication(value,sum,arithmetic)<<endl;
		break;
	case '/':
		cout<<division(value,sum,arithmetic)<<endl;
		break;
	case '^':
		cout<<sumsquared(value,sum,arithmetic)<<endl;
		break;
	case '<':
		lessthanrelation(value,sum,relational);
		break;
	case '>':
		greaterthanrelation(value,sum,relational);
		break;
	case 'c':
		cout<<clearsum(sum);
		break;
	case 'q':
		cout<<quit(arithmetic,relational,cont);
		break;
		
	}
	}
	

	return 0;
}

double addition(double&value,double& sum,int&arithmetic)
{
	cout<<"Enter Value"<<endl;
	cin>>value;
	sum+=value;
    cout<<"Current Value: ";
	arithmetic++;
return sum;
}
double subtraction(double&value,double&sum,int&arithmetic)
{
	cout<<"Enter Value"<<endl;
	cin>>value;
	sum=sum-value;
	cout<<"Current Value: ";
	arithmetic++;
	return sum;
}
double multiplication(double&value,double&sum,int&arithmetic)
{
	cout<<"Enter a value"<<endl;
	cin>>value;
	sum=sum*value;
	cout<<"Current Value: ";
	arithmetic++;
		return sum;
}
double division(double&value,double&sum,int&arithmetic)
{
	cout<<"Enter a value"<<endl;
	cin>>value;
	sum=sum/value;
	cout<<"Current Value: ";
	arithmetic++;
	return sum;
}
double sumsquared(double&value,double&sum,int&arithmetic)
{
	cout<<"Enter a value"<<endl;
	cin>>value;
	sum=pow(sum,value);
	cout<<"Current Value: ";
	arithmetic++;
	return sum;
}
void lessthanrelation(double&value,double&sum,int&relational)
{
	relational++;
	cout<<"Enter a value"<<endl;
	cin>>value;
	if(sum<value)
		cout<<"True"<<endl;
	else 
		cout<<"False"<<endl;

}
void greaterthanrelation(double&value,double&sum,int&relational)
{
	relational++;
	cout<<"Enter a value"<<endl;
	cin>>value;
	if(sum>value)
		cout<<"True"<<endl;
	else
		cout<<"False"<<endl;
}
double clearsum(double&sum)
{
	sum=0;
	cout<<"Sum is now set to"<<sum<<endl;
	return sum;
}
double quit(int&arithmetic,int&relational,char cont)
{
	cont='p';
	cout<<"You have performed "<<arithmetic<<" arithmetic operations"<<endl;
	cout<<"You have performed "<<relational<<" relational operations"<<endl;
	return cont;
}
void convdouble(int&value)
{
any1?
closed account (o1vk4iN6)
Ask your prof/teacher for more information on the specifications they want.

To me it sounds like you just need to check if there's a "." in the input, just how you would define a double in C++.

 
double v = 1.;
Topic archived. No new replies allowed.