Square root help

Hi, (I am new here be gentle! I have looked here before and cannot find the help i need) I have this calculator that i have for my class, and i need to have a square root integrated in it... But every time that i try to integrate the sqrt() command I can't get it to select a specific number for the user to find the sqrt of... So I'm getting frustrated without this program working to the extent i want it to.

(What I have so far idk if it's needed)

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
#include <iostream>
#include <conio.h>
#include <math.h>
using namespace std;
void main(){

	double dFirst, dSecond; int cond;
		system("color 09");
	do{ system("cls");
		cout << "\n\n\n1. Add";
		cout << "\n\n\n2. Subtract";
		cout << "\n\n\n3. Multiply";
		cout << "\n\n\n4. Devide";
		cout << "\n\n\n5. Multiplication Tables";
		cout << "\n\n\n6. Sqrt";
		cout << "\n\n\nEnter choice: "; cin >> cond;
	
		if(cond == 1) { system("cls");
 
			cout << "\n\n\nAddition";
			cout << "\n\n\nEnter first number: "; cin >> dFirst;
			cout << "\n\n\nEnter in second number: "; cin >> dSecond;
			cout << "\n\n\n" << dFirst << " + " << dSecond << " = " << dFirst + dSecond << "\n\n"; system("pause");
	 } 

		if(cond == 2) { system("cls");
 
			cout << "\n\n\nSubtraction";
			cout << "\n\n\nEnter first number: "; cin >> dFirst;
			cout << "\n\n\nEnter in second number: "; cin >> dSecond;
			cout << "\n\n\n" << dFirst << " - " << dSecond << " = " << dFirst - dSecond << "\n\n"; system("pause");
 }
		if(cond == 3) { system("cls");
 
			cout << "\n\n\nMultiplication";
			cout << "\n\n\nEnter first number: "; cin >> dFirst;
			cout << "\n\n\nEnter in second number: "; cin >> dSecond;
			cout << "\n\n\n" << dFirst << " x " << dSecond << " = " << dFirst * dSecond << "\n\n"; system("pause");

 }
	if(cond == 4) { system("cls");
 
		cout << "\n\n\nDivision";
		cout << "\n\n\nEnter first number: "; cin >> dFirst;
		cout << "\n\n\nEnter in second number: "; cin >> dSecond;
		cout << "\n\n\n" << dFirst << " / " << dSecond << " = " << dFirst / dSecond << "\n\n"; system("pause");
				  }
	if(cond ==5) { system("cls");
	for (int i = 1; i <= 10; i++){

		for(int a = 1; a <= 10; a++)

			cout << i * a << "\t";
		cout << "\n";
	}

	system("pause");}

		if(cond > 6){
			cout << "\n\nError, no correct value selected\n\n";
		}
		if(cond < 1){
			cout << "\n\nError, no correct value selected\n\n";
	 }
	}while(cond != 6);
           }
Last edited on
A few small issues first:
1) use <cmath> instead of <math.h> when working in C++
2) it should be int main() not void main().
3) Don't use system("anything"). It isn't safe and will be flagged by your anti-virus program if used enough
4) Indenting is important. I had some trouble figuring out which } belonged to which {.

Here is your code with some slight formatting and cond==6 statement:
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
#include <iostream>
#include <conio.h>
#include <math.h>
using namespace std;
void main(){

  double dFirst, dSecond; int cond;
  system("color 09");
  do{ 
    system("cls");
    cout << "\n\n\n1. Add";
    cout << "\n\n\n2. Subtract";
    cout << "\n\n\n3. Multiply";
    cout << "\n\n\n4. Devide";
    cout << "\n\n\n5. Multiplication Tables";
    cout << "\n\n\n6. Sqrt";
    cout << "\n\n\nEnter choice: "; cin >> cond;

    if(cond == 1) 
    { 
      system("cls");
      cout << "\n\n\nAddition";
      cout << "\n\n\nEnter first number: "; cin >> dFirst;
      cout << "\n\n\nEnter in second number: "; cin >> dSecond;
      cout << "\n\n\n" << dFirst << " + " << dSecond << " = " << dFirst + dSecond << "\n\n"; 
      system("pause");
    } 

    if(cond == 2) 
    { 
      system("cls");
      cout << "\n\n\nSubtraction";
      cout << "\n\n\nEnter first number: "; cin >> dFirst;
      cout << "\n\n\nEnter in second number: "; cin >> dSecond;
      cout << "\n\n\n" << dFirst << " - " << dSecond << " = " << dFirst - dSecond << "\n\n"; 
      system("pause");
    }
    if(cond == 3) 
    { 
      system("cls");
      cout << "\n\n\nMultiplication";
      cout << "\n\n\nEnter first number: "; cin >> dFirst;
      cout << "\n\n\nEnter in second number: "; cin >> dSecond;
      cout << "\n\n\n" << dFirst << " x " << dSecond << " = " << dFirst * dSecond << "\n\n"; 
      system("pause");
    }
    if(cond == 4) 
    { 
      system("cls");
      cout << "\n\n\nDivision";
      cout << "\n\n\nEnter first number: "; cin >> dFirst;
      cout << "\n\n\nEnter in second number: "; cin >> dSecond;
      cout << "\n\n\n" << dFirst << " / " << dSecond << " = " << dFirst / dSecond << "\n\n"; 
      system("pause");
    }
    if(cond ==5) 
    { 
      system("cls");
      for (int i = 1; i <= 10; i++)
      {
        for(int a = 1; a <= 10; a++)
          cout << i * a << "\t";
        cout << "\n";
      }
      system("pause");
    }
    if(cond == 6)
    {
      system("cls");
      cout << "\n\n\nSquare root";
      cout << "\n\n\nEnter the number: "; cin >> dFirst;
      cout << "\n\n\nsqrt(" << dFirst << ") = " << sqrt(dFirst) << "\n\n";
      system("pause");
    }
    
    if(cond > 6)
    {
      cout << "\n\nError, no correct value selected\n\n";
    }
    if(cond < 1)
    {
      cout << "\n\nError, no correct value selected\n\n";
    }
  }while(cond != 6);
}
Topic archived. No new replies allowed.