I can't run my calculator program using switch

Good afternoon everybody, I am using CODE::BLOCKS 10.05 for UBUNTU and I'm trying to build a calculator using the option switch and a boolean form, I started making each operation in independent projects and those worked fine, one project for addition, subtraction, multiply, division and square root, independently each one worked fine just with the option GOTO tryagain and exit in each case. But when putting everything together and building just one menu I had a problem running it, I worked all along the incoming errors when trying to build until the end in the last two brackets LINE 174, I got a bracket issue that I tried to solve looking for some missing brackets around with no success.

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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include <iostream>//Includes common functions and such
 using namespace std;//Use the std namespace
int input;
int main()//Program entry point
 //{ double x;
// double mult ( double x, double y );
// double square (double x);


//	return x*x;

// void print_square(double x)

{ bool done=false;//loop quit variable
 while(done!=true)//The main program loop.
 {

            cout<<"              This is my FIRST STEP to a Higher programming skills ";
            cout<<"please hit ENTER to continue... "<<"\n";
            cout<<"\n";

  cout << "1 - Addition.\n2 - Substraction.\n3 - Division.\n4 - Multiplication.\n5 - Squareroot.\n6 - Quit.\n";//This is the menu
   int choice=0; //Declare the variable choice and set its value to 0
   cin >> choice;//Get the user input and put it in choice
   switch(choice)
   {

   case 1: //Addition

        double x;
        double y;

  cout<<"This is a decimal and whole numbers sum calculator "<<"\n";
  cout<<"\n";


  cout<<"Please input one of the two numbers to be added, then hit ENTER: ";

  cin>> x;
  cout<<"\n";
  cout<<"Please input the second of the two numbers to be added,then hit ENTER: ";

  cin>> y;
  cin.ignore();
  cout<<"\n";
  cout<<"\n";
  cout<<"The result of adding  "<< x <<"  and... "<< y <<" is = to "<<  ( x + y ) <<"\n";
  cout<<"\n";
  cout<<"\n";
  cout<<"Then the product of your two numbers is  "<< ( x + y ) <<"\n";
  cout<<"\n";
  cout<<"Please hit ENTER to decide what do you want to do next, select your number option and then press ENTER again... "<<"\n";
  cin.get();
    break;
    case 2:

    cout<<"This is a decimal and whole numbers Substraction calculator "<<"\n";
    cout<<"\n";


    cout<<"Please input one of the two numbers to be substracted, then hit ENTER: ";

    cin>> x;
    cout<<"\n";
    cout<<"Please input the second of the two numbers to be substracted,then hit ENTER: ";

    cin>> y;
    cin.ignore();
    cout<<"\n";
    cout<<"\n";
    cout<<"The result of substracting  "<< x <<"  and... "<< y <<" is = to "<<  ( x - y ) <<"\n";
    cout<<"\n";
    cout<<"\n";
    cout<<"Then the product of your two numbers is  "<< ( x - y ) <<"\n";
    cout<<"\n";
    cout<<"Please hit ENTER to decide what do you want to do next, select your number option and then press ENTER again... "<<"\n";
    cin.get();
    break;
    case 3:
            cout<<"This is a decimal and whole numbers division calculator "<<"\n";
  cout<<"\n";


  cout<<"Please input one of the two numbers to be divided, then hit ENTER: ";

  cin>> x;
  cout<<"\n";
  cout<<"Please input the second of the two numbers to be divided,then hit ENTER: ";

  cin>> y;
  cin.ignore();
  cout<<"\n";
  cout<<"\n";
  cout<<"The result of dividing  "<< x <<"  and... "<< y <<" is = to "<<  ( x / y ) <<"\n";
  cout<<"\n";
  cout<<"\n";
  cout<<"Then the product of your two numbers is  "<< ( x / y ) <<"\n";
  cout<<"\n";
  cout<<"Please hit ENTER to decide what do you want to do next, select your number option and then press ENTER again... "<<"\n";
  cin.get();
        break;
        case 4:
        double mult ( double x, double y );
        cout<<"This is a decimal and whole numbers multiplier calculator "<<"\n";
  cout<<"\n";


  cout<<"Please input one of the two numbers to be multiplied, then hit ENTER: ";

  cin>> x;
  cout<<"\n";
  cout<<"Please input the second of the two numbers to be multiplied,then hit ENTER: ";

  cin>> y;
  cin.ignore();
  cout<<"\n";
  cout<<"\n";
  cout<<"The result of multiplying  "<< x <<"  and... "<< y <<" is = to "<< mult ( x, y ) <<"\n";
  cout<<"\n";
  cout<<"\n";
  cout<<"Then the product of your two numbers is  "<< mult ( x, y ) <<"\n";
  cout<<"\n";
  cout<<"Please hit ENTER to decide what do you want to do next, select your number option and then press ENTER again... "<<"\n";
  cin.get();
    break;
    case 5:

{
	return x*x;
}
void print_square(double x);
double square (double x);

	cout<< "the square of " << x <<" is " << square(x) << " \n ";

//int input;
//int main()

//    double x;



  cin.ignore();

  // tryAgain:

  cout<<"This is a Square root calculator "<<"\n";
  cout<<"\n";


  cout<<"Please input a number to be root squared then hit ENTER: ";

  cin>> x;
  cout<<"\n";

  cin.ignore();
  cout<<"\n";
  cout<<"\n";
  cout<<"The result of root square  "<< x <<" is = to "<< square (x) <<"\n";
  cout<<"\n";
  cout<<"\n";
  //cout<<"Then the product of your two numbers is  "<< mult ( x, y ) <<"\n";
  cout<<"\n";
  cout<<"Please hit ENTER to decide what do you want to do next, select your number option and then press ENTER again... "<<"\n";
  cin.get();
    break;
    case 6:
    cout<<"Thank you, see you soon!\n";
    break;
  default:            // Note the colon, not a semicolon
    cout<<"Error, bad input, quitting\n";
    break;

   }    //******here is line 174****** 
 }
//   cin.get();

Last edited on
You have unbalanced brackets there is more '{' than '}'.

Also lines 131-132. While it is completely legal, why you did that?
That is one long switch statement lol. Anyways, first problem is at line 7 where you define it. You define it local to main and you can't do that. It needs to to be defined outside of any other function. You do hat multiple times throughout your code. Lastly, your brackets are... confusing to say the least. Line 128-130: to what do those brackets belong to? I'm assuming you want to return from your void print_square(double x) because that's the only function call above it. But again you can't define that function inside of main() or any other function.

EDIT:
Basically what MiiNiPaa said. Your brackets are off.
Last edited on
closed account (iAk3T05o)
Your program is unreasonably longer and confusing than it should be.
What's all those cout << "\n"; everywhere?
Thank you for all your advise, I just realized that as Renthalkx97 said I can't define it local to main..and then I am trying to solve the problem defining that outside of any other function.. answering Nathan222(261) I used a lot of cout to make the screen look different when replying an answer..instead of just showing the result, I wanted to say here is what you put in and using this numbers that you used this are your answers...Answering MiiniPaa (3036) probably I just copied and paste from the original independent function that worked before trying to put all together and let that to keep going or to stop an error.
Topic archived. No new replies allowed.