HELP I got tired of fixing it.. T_T

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
#include<iostream.h>
#include<conio.h>

main()
{
	clrscr();
	int number;
	char re;
	cout<<"multiplication table[1]"<<endl;
	cout<<"EXIT[2]"<<endl;
	cin>>number;

	do{
	switch(number)
	{
	case 1:
	int number;
	cout<<"Enter the number 5:"<<endl;
	cin>>number;
	if (5 == number);
	cout<<"5 multiplied by 0 is equal to 0"<<endl;
	cout<<"5 multiplied by 1 is equal to 5"<<endl;
	cout<<"5 multiplied by 2 is equal to 10"<<endl;
	cout<<"5 multiplied by 3 is equal to 15"<<endl;
	cout<<"5 multiplied by 4 is equal to 20"<<endl;
	cout<<"5 multiplied by 5 is equal to 25"<<endl;
	cout<<"5 multiplied by 6 is equal to 30"<<endl;
	cout<<"5 multiplied by 7 is equal to 35"<<endl;
	cout<<"5 multiplied by 8 is equal to 40"<<endl;
	cout<<"5 multiplied by 9 is equal to 45"<<endl;
	cout<<"5 multiplied by 10 is equal to 50"<<endl;


	else;
	default:
	cout<<"Invalid Output"<<endl;
	break;
	}

	cout<<"Do you want to continue?[Y/N]"<<endl;
	cin>>re;

	}while(re=='Y'||re=='y');

	getch();
	return 0;
	}
I don't see anywhere in your post a description of the problem. Please explain the current problem and then explain the desired behavior.
the problem here is that the invalid output are not working properly as I want
it suppose to be invalid when you type other number except for the number 5 and the exit should have the termination of "do you want to continue?[Y/N]" when I press y and enter it looped again to the same statement of "Do you want to continue?[Y/N].
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

#include<iostream.h>
#include<conio.h>

main()
{
	clrscr();
	int number;
	char re;
	cout<<"multiplication table[1]"<<endl;
	cout<<"EXIT[2]"<<endl;
	cin>>number;

	do{
	switch(number)
	{
	case 1:
	int number;
	cout<<"Enter the number 5:"<<endl;
	cin>>number;
	if (5 == number);
	{  //Braces added
        cout<<"5 multiplied by 0 is equal to 0"<<endl;
	cout<<"5 multiplied by 1 is equal to 5"<<endl;
	cout<<"5 multiplied by 2 is equal to 10"<<endl;
	cout<<"5 multiplied by 3 is equal to 15"<<endl;
	cout<<"5 multiplied by 4 is equal to 20"<<endl;
	cout<<"5 multiplied by 5 is equal to 25"<<endl;
	cout<<"5 multiplied by 6 is equal to 30"<<endl;
	cout<<"5 multiplied by 7 is equal to 35"<<endl;
	cout<<"5 multiplied by 8 is equal to 40"<<endl;
	cout<<"5 multiplied by 9 is equal to 45"<<endl;
	cout<<"5 multiplied by 10 is equal to 50"<<endl;
        }

	else;
	default:
	cout<<"Invalid Output"<<endl;
	break;
	}

	cout<<"Do you want to continue?[Y/N]"<<endl;
	cin>>re;

	}while(re=='Y'||re=='y');   //If you want to exit if y is pressed, then replace (Y,y) with (N.n)

	getch();
	return 0;
	}


And as for the exit thing. It says Do you want to continue(Y/N) and if you press Y, it continues. what is the problem then? Do you want it to exit if Y is pressed? If yes then, do as commented in the while statement.
If it works for you then I need you to find out why it worked. Consider it as homework. ;)
Last edited on
And one other thing
when i try to run the program it has 1 error and that is the else; it said that I misplaced else. What should I do?
Last edited on
a) No ';' after your if statement (line 21 in Pravesh' code snippet).
b) No empty 'else'. An if can be by itself. If you don't need an 'else' case, don't use one.
c) If you need your cases to be strictly separated, make sure to add a 'break;' at the end of each case.
If I do that the my invalid output won't be shown if I type any number except number 5
and my invalid input will be in exit if I type 2.
Topic archived. No new replies allowed.