menu

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
#include <cstdlib>
#include <iostream>

using namespace std;
void factorial ();
int main()
{
     char ch;
     cout <<"pasirinkite viena varianta is a,b,c\n"<<endl;
     cout <<"noredami nutraukti darba iveskite #\n"<<endl;
     while ((ch=getchar())!='#')
     {
           if(ch!=' ')
           switch(ch)
           {
                     case 'a':printf("Skaiciaus kubas\n");
                     break;
                     case 'b':printf("Kvadratine saknis\n");
                     break;
                     case 'c':printf("Faktorialas\n");factorial ();
                     break;
                     }
                           else
                           cout << "Jus ivedete tarpo klavisa, noredami testi iveskite raide , arba noredami baigti #\n"<<endl;
                           }
                           }

#include <iostream>
using namespace std; 


void factorial ();


{
	int number = 1; 
	


    cout << "Irasykite skaiciu: ";
	cin >> number;

    if (number < 0)
		cout << "That is not a positive integer.\n";

    else
		cout << number << " Faktorialas yra: " << factorial(number) << endl;




int factorial (int number)

   int y = 1;

     if  (number <= 1)
		 return 1;

	 y = number * factorial(number - 1);
	   return y;
}

here it creates a menu , and in case 'c' it should count a factorial , I added a function , but something is wrong , help please.
Last edited on
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
#include <cstdlib>
#include <iostream>
using namespace std;

int factorial (int number);
void factorial ();

int main()
{
	char ch;
	cout <<"pasirinkite viena varianta is a,b,c"<<endl;
	cout <<"noredami nutraukti darba iveskite #"<<endl;
	while ((ch=getchar())!='#')
	{
		if(ch!=' ')
		switch(ch)
		{
			case 'a':printf("Skaiciaus kubas\n");
				break;
			case 'b':printf("Kvadratine saknis\n");
				break;
			case 'c':printf("Faktorialas\n");factorial ();
				break;
		}
		else
			cout << "Jus ivedete tarpo klavisa, noredami testi iveskite raide , arba noredami baigti #\n"<<endl;
	}
}

void factorial (){
	int number = 1; 

    cout << "Irasykite skaiciu: ";
	cin >> number;

    if (number < 0)
		cout << "That is not a positive integer.\n";
    else
		cout << number << " Faktorialas yra: " << factorial(number) << endl;
}


int factorial (int number){
   int y = 1;
     if  (number <= 1)
		 return 1;

	 y = number * factorial(number - 1);
	   return y;
}
thank you.
btw you shouldn't write stuf in Lithuanian. it would be easyer to understand the program.
Topic archived. No new replies allowed.