Choice Problem

closed account (EwCjE3v7)
When I do a sum and than it tells me would u like to try again and when i type n it does not work it goes to funtion main again..THank you..
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
  #include <iostream>
using namespace std;
int main();

int adding ()
{
	int n1, n2;
	cout << "\nType two new numbers to add: \n" << endl;
	cin >> n1 >> n2;
	cout << n1 << " + " << n2 << " equels " << n1 + n2 << endl;

	char choice = 'a';
    cout << "\nWould you like to try again \ny for yes, n for no: " << endl;
    cin >> choice;
    if (choice = 'y' || choice == 'Y') {
        main ();
    } else {
        cout << "\nBye Bye" << endl;
    }

	return 0;
}

int subtracting ()
{
	int n1, n2;
	cout << "\nType two new numbers to subtract: \n" << endl;
	cin >> n1 >> n2;
	cout << n1 << " - " << n2 << " equels " << n1 - n2 << endl;

	char choice = 'a';
    cout << "\nWould you like to try again \ny for yes, n for no: " << endl;
    cin >> choice;
    if (choice = 'y' || choice == 'Y') {
        main ();
    } else {
        cout << "\nBye Bye" << endl;
    }

	return 0;
}

int multiplycation ()
{
	int n1, n2;
	cout << "\nType two new numbers to multiply: \n" << endl;
	cin >> n1 >> n2;
	cout << n1 << " * " << n2 << " equels " << n1 * n2 << endl;

	char choice = 'a';
    cout << "\nWould you like to try again \ny for yes, n for no: " << endl;
    cin >> choice;
    if (choice = 'y' || choice == 'Y') {
        main ();
    } else {
        cout << "\nBye Bye" << endl;
    }

	return 0;
}

int devision ()
{
    int n1, n2;
    cout << "\nType two new numbers to devide: \n First one bigger than second \n" << endl;
    cin >> n1 >> n2;
    cout << n1 << " / " << n2 << " equels " << n1 / n2 << endl;

    char choice = 'a';
    cout << "\nWould you like to try again \ny for yes, n for no: " << endl;
    cin >> choice;
    if (choice = 'y' || choice == 'Y') {
        main ();
    } else {
        cout << "\nBye Bye" << endl;
    }

	return 0;
}

int main()
{
	cout << "Type \na for adding \ns for subtracting \nm for multiply \nd for divide \n" << endl;
	char choice = 'y';
	cin >> choice;

	if (choice == 'a' || choice == 'A')
	{
		adding ();
	}
	else if (choice == 's' || choice == 'S')
	{
		subtracting ();
	}
	else if (choice == 'm' || choice == 'M')
	{
		multiplycation ();
	}
	else if (choice == 'd' || choice == 'D')
	{
		devision ();
	}
	else
	{
		cout << "Only  a,s,m,d" << endl;
	}

	return 0;
}
closed account (1v5E3TCk)
Edited working
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
 #include <iostream>
using namespace std;

int adding ()
{
	int n1, n2;
	cout << "\nType two new numbers to add: \n" << endl;
	cin >> n1 >> n2;
	cout << n1 << " + " << n2 << " equels " << n1 + n2 << endl;

	char choice;
    cout << "\nWould you like to try again \ny for yes, n for no: " << endl;
    cin >> choice;
    if (choice == 'y' || choice == 'Y') {
        return 1;
    } else {
        cout << "\nBye Bye" << endl;
        return 0;
}


}

int subtracting ()
{
	int n1, n2;
	cout << "\nType two new numbers to subtract: \n" << endl;
	cin >> n1 >> n2;
	cout << n1 << " - " << n2 << " equels " << n1 - n2 << endl;

	char choice;
    cout << "\nWould you like to try again \ny for yes, n for no: " << endl;
    cin >> choice;
    if (choice == 'y' || choice == 'Y') {
        return 1;
    } else {
        cout << "\nBye Bye" << endl;
  return 0;
  }


}

int multiplycation ()
{
	int n1, n2;
	cout << "\nType two new numbers to multiply: \n" << endl;
	cin >> n1 >> n2;
	cout << n1 << " * " << n2 << " equels " << n1 * n2 << endl;

	char choice;
    cout << "\nWould you like to try again \ny for yes, n for no: " << endl;
    cin >> choice;
    if (choice == 'y' || choice == 'Y') {
        return 1;
    } else {
        cout << "\nBye Bye" << endl;
        return 0;
  }


}

int devision ()
{
    int n1, n2;
    cout << "\nType two new numbers to devide: \n First one bigger than second \n" << endl;
    cin >> n1 >> n2;
    cout << n1 << " / " << n2 << " equels " << n1 / n2 << endl;

    char choice;
    cout << "\nWould you like to try again \ny for yes, n for no: " << endl;
    cin >> choice;
    if (choice == 'y' || choice == 'Y') {
        return 1;
    } else {
        cout << "\nBye Bye" << endl;
        return 0;
    }


}

int main()
{

int wanna;

while( 1 )
{
    cout << "Type \na for adding \ns for subtracting \nm for multiply \nd for divide \n" << endl;
	char choice;
	cin >> choice;

	if (choice == 'a' || choice == 'A')
	{
		wanna = adding();
		if( wanna == 0)
        {
            break;
        }
        



	}
	else if (choice == 's' || choice == 'S')
	{
		wanna = subtracting ();
        if( wanna == 0 )
        {
            break;

        }
	}
	else if (choice == 'm' || choice == 'M')
	{
		wanna = multiplycation ();
        if( wanna == 0 )
        {
            break;

        }
	}
	else if (choice == 'd' || choice == 'D')
	{
		wanna = devision ();
        if( wanna == 0 )
        {
            break;

        }
	}
	else
	{
		cout << "Only  a,s,m,d" << endl;
	}



}


	return 0;
}
Last edited on
closed account (EwCjE3v7)
Nope it dosnt work..

Solved by senhor on skype...i wrote
1
2
3
 if (choice = 'y' || choice == 'Y') {
        main ();
    }


but it must be
1
2
3
 if (choice == 'y' || choice == 'Y') {
        main ();
    }


Correct COde
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
#include <iostream>
using namespace std;
int main();

int adding ()
{
	int n1, n2;
	cout << "\nType two new numbers to add: \n" << endl;
	cin >> n1 >> n2;
	cout << n1 << " + " << n2 << " equels " << n1 + n2 << endl;

	char choice = 'a';
    cout << "\nWould you like to try again \ny for yes, n for no: " << endl;
    cin >> choice;
    if (choice == 'y' || choice == 'Y') {
        main ();
    } else {
        cout << "\nBye Bye" << endl;
    }

	return 0;
}

int subtracting ()
{
	int n1, n2;
	cout << "\nType two new numbers to subtract: \n" << endl;
	cin >> n1 >> n2;
	cout << n1 << " - " << n2 << " equels " << n1 - n2 << endl;

	char choice = 'a';
    cout << "\nWould you like to try again \ny for yes, n for no: " << endl;
    cin >> choice;
    if (choice == 'y' || choice == 'Y') {
        main ();
    } else {
        cout << "\nBye Bye" << endl;
    }

	return 0;
}

int multiplycation ()
{
	int n1, n2;
	cout << "\nType two new numbers to multiply: \n" << endl;
	cin >> n1 >> n2;
	cout << n1 << " * " << n2 << " equels " << n1 * n2 << endl;

	char choice = 'a';
    cout << "\nWould you like to try again \ny for yes, n for no: " << endl;
    cin >> choice;
    if (choice == 'y' || choice == 'Y') {
        main ();
    } else {
        cout << "\nBye Bye" << endl;
    }

	return 0;
}

int devision ()
{
    int n1, n2;
    cout << "\nType two new numbers to devide: \n First one bigger than second \n" << endl;
    cin >> n1 >> n2;
    cout << n1 << " / " << n2 << " equels " << n1 / n2 << endl;

    char choice = 'a';
    cout << "\nWould you like to try again \ny for yes, n for no: " << endl;
    cin >> choice;
    if (choice == 'y' || choice == 'Y') {
        main ();
    } else {
        cout << "\nBye Bye" << endl;
    }

	return 0;
}

int main()
{
	cout << "Type \na for adding \ns for subtracting \nm for multiply \nd for divide \n" << endl;
	char choice = 'y';
	cin >> choice;

	if (choice == 'a' || choice == 'A')
	{
		adding ();
	}
	else if (choice == 's' || choice == 'S')
	{
		subtracting ();
	}
	else if (choice == 'm' || choice == 'M')
	{
		multiplycation ();
	}
	else if (choice == 'd' || choice == 'D')
	{
		devision ();
	}
	else
	{
		cout << "Only  a,s,m,d" << endl;
	}


	return 0;
}
Last edited on
In C++, you may not call main. The standard forbids it.
closed account (1v5E3TCk)

In C++, you may not call main. The standard forbids it.


I said that to him lol.
closed account (EwCjE3v7)
But how come it works?
But how come it works?

Why do you not get hit by a truck every time you wander into a street while blindfolded?

Undefined behavior may appear to do what you expect. It is still undefined behavior.
closed account (EwCjE3v7)
@cire

OK i get it
Topic archived. No new replies allowed.