"Type crar not a const"

Can you help fix this?

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
// Simple math script to help me get use
// to using funcltions! 

#include <cstdlib>
#include <cstdio>
#include <iostream>

using namespace std; // Should I stop using 
			         // in future scripts?

char operation; // (+ - * /)

double sum, num1, num2;	

void explainCal(void) //Begining message.
{
	cout << "This is a very basic calculater"
	     << " able to add, subtract, multiply"
		 << ", and divide small numbers quicly."
		 << "\nEnter Problem:\t";
}

void calculateProb(void) // Calculates are
{				   // Problem.
	case( operation == '+') //Add
	{
		sum = num1 + num2;
		break;
	}
	
	case( operation == '-') //Subtract
	{
		sum = num1 - num2;
		break;
	}
	
	case( operation == '*') // Multiply
	{
		sum = num1 * num2;
		break;
	}
	
	case( operation == '/') // Divide
	{
		sum = num1 / num2;
		break;
	}
	
	default //If all else goes wrong!
	{
		cout << "Error: Unable to complete!";
	}
	
	return ;
}

int main ()
{
	explainCal(); 
	
	cin >> num1 >> operation 
	    >> num2; // Grabs problem.
		
	calculateProb();
	
	cout << "\n The answer:\t"
	     << sum; //Prints answer.
	
	return 0;
}
Last edited on
Your calculateProb function doesn't implement the switch statement correctly.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void calculateProb()
{
    switch(operation)
    {
    case '+':
        //do addition stuff
        break;
    case '-':
        //do subtraction stuff
        break;
    //etc...
    default:
        //print error message
        break;
    }
}
Last edited on
closed account (E0p9LyTq)
You are using case statements as if statements.

http://www.cplusplus.com/doc/tutorial/control/

Last edited on
closed account (E0p9LyTq)
using namespace std; // Should I stop using
// in future scripts?


Yes.

http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice
fixed!

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
// Simple math script to help me get use
// to using funcltions! 

#include <cstdlib>
#include <cstdio>
#include <iostream>

using namespace std; // Should I stop using 
					 // in future scripts?

char operation; // (+ - * /)

double sum, num1, num2;	

void explainCal(void) //Begining message.
{
	cout << "This is a very basic calculater"
	     << " able to add, subtract, multiply"
		 << ", and divide small numbers quicly."
		 << "\nEnter Problem:\t";
}

void calculateProb(void) 
{	
    switch (operation)
    {
	case '+': //Add
		sum = num1 + num2;
		break;
	
	case '-': //Subtract
		sum = num1 - num2;
		break;
	
	case '*': // Multiply
		sum = num1 * num2;
		break;
	
	case '/': // Divide
		sum = num1 / num2;
		break;
	
	default: //If all else goes wrong!
		cout << "Error: Unable to complete!";
	}
	
	return ;
}

int main ()
{
	explainCal(); 
	
	cin >> num1 >> operation 
	    >> num2; // Grabs problem.
		
	calculateProb();
	
	cout << "\n The answer:\t"
	     << sum; //Prints answer.
	
	return 0;
}
Topic archived. No new replies allowed.