cout problem

this is my program.

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

using namespace std;

int main()
{

int num, isPrime,i,n=10, max=0, min=99, even=0, odd=0;
int qa=0, qb=0, qc=0, qd=0, qe=0;
cout<<"Note that prime number will refer as [1], Not prime number will refer as [0]"<<endl;
cout << "Enter 20 integer numbers from 0 to 99: "<<endl;

for (i=1;i<=n;i++)
{

cout << "Input " << i <<":";
cin >> num;

if (num>max)
max=num;
if (num<min)
min=num;
if (num%2==0)
even++;
else
odd++;


int isPrime=1;

if (num==0)
{
isPrime=0;
}

if (num==1)
{
isPrime=0;

}
if (num%2==0)
{
isPrime=0;
}
if(num==2)
{
isPrime=1;
}

for(int i=2;i<(num/2);i++)
{
if(num%i==0 )
{
//not prime number
isPrime=0;
break;
}

}

}
cout<<"["<<isPrime<<"]"<<endl;







switch(num)
{
case 0:
if(num%8==0)
qa++;
break;
case 1:
if(num%8==1)
qb++;
case 2:
if (num%8==2)
qc++;
case 3:
if (num%8==3)
qd++;
default:
qe++;
break;
}

}

cout<<num<<endl;
cout<<"max is"<<max<<endl;
cout<<"min is"<<min<<endl;
cout<<"Total number of even is "<<even<<endl;
cout<<"Total number of odd is "<<odd<<endl;
cout<<"Numbers that have remainders of 0"<<endl;
cout<<q0<<endl;
cout<<"Numbers that have remainders of 1"<<endl;
cout<<q1<<endl;
cout<<"Numbers that have remainders of others"<<endl;
cout<<qd<<endl;


getch();
cin.get();
}



but my problem, i can't get to display my answer. when i write the switch fn, all the cout have the red line under it. i dont know how to fix it.
Please past your code in code tags

there the <> symbol, your code is very hard to read.
Last edited on
Ok well first of all your cout statements were outside of main, so thats why you were having the errors.

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

using namespace std;

int main()
{

    int num, isPrime,i,n=10, max=0, min=99, even=0, odd=0;
    int qa=0, qb=0, qc=0, qd=0, qe=0;

    cout<<"Note that prime number will refer as [1], Not prime number will refer as [0]"<<endl;
    cout << "Enter 20 integer numbers from 0 to 99: "<<endl;

    for (i=1;i<=n;i++)
    {
        cout << "Input " << i <<":";
        cin >> num;

        if (num>max)
            max=num;
        if (num<min)
            min=num;
        if (num%2==0)
            even++;
        else
            odd++;


        int isPrime=1;

        if (num==0)
        {
            isPrime=0;
        }

        if (num==1)
        {
            isPrime=0;
        }

        if (num%2==0)
        {
            isPrime=0;
        }

        if(num==2)
        {
            isPrime=1;
        }

    for(int i=2;i<(num/2);i++)
    {
        if(num%i==0 )
    {
    //not prime number
        isPrime=0;
        break;
    }

    }

    }

cout<<"["<<isPrime<<"]"<<endl;

switch(num)
{
case 0:
if(num%8==0)
qa++;
break;
case 1:
if(num%8==1)
qb++;
case 2:
if (num%8==2)
qc++;
case 3:
if (num%8==3)
qd++;
default:
qe++;
break;
}

cout<<num<<endl;
cout<<"max is"<<max<<endl;
cout<<"min is"<<min<<endl;
cout<<"Total number of even is "<<even<<endl;
cout<<"Total number of odd is "<<odd<<endl;
cout<<"Numbers that have remainders of 0"<<endl;
cout<<q0<<endl;
cout<<"Numbers that have remainders of 1"<<endl;
cout<<q1<<endl;
cout<<"Numbers that have remainders of others"<<endl;
cout<<qd<<endl;


getch();
cin.get();

}


There are just 2 errors now, im sure you can fix them.

In function 'int main()':|
error: 'q0' was not declared in this scope|
error: 'q1' was not declared in this scope|

Last edited on
i try to fix it, but it didn't display the output for q0-q4. do i have to put the cout for q0-q4 in the for loop?
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
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
	int num, isPrime,i,n=5, max=0, min=99, even=0, odd=0; 
	int q0=0, q1=0, q2=0, q3=0, q4=0;
	cout<<"Note that:"<<endl;
	cout<<"Prime number will refer as [1]"<<endl;
	cout<<"Not prime number will refer as [0]"<<endl<<endl;
	cout << "Enter 20 integer numbers from 0 to 99: "<<endl;
	
    for (i=1;i<=n;i++)
    {
       	cout << "Input " << i <<":";
		cin >> num;
		
		if(num>99)
			break;
		if (num>max)
		max=num;
		if (num<min)
		min=num;
		if (num%2==0)
			even++;
		else
			odd++;

		int isPrime=1;

		if (num==0)
		{
			isPrime=0;
		}

		if (num==1)
		{
			isPrime=0;
			
		}
		if (num%2==0)
		{
			isPrime=0;
		}
		if(num==2)
		{
			isPrime=1;
		}

		
		for(int i=2;i<(num/2);i++)
		{
			if(num%i==0 )
			{
		//not prime number
				isPrime=0;
				break;
			}
			
		}
		
		cout<<"["<<isPrime<<"]"<<endl;

		switch(num)
		{
		case 0:
			if(num%8==0)
				q0++;
			break;
		case 1:
			if(num%8==1)
				q1++;
		case 2:
			if (num%8==2)
				q2++;
		case 3:
			if (num%8==3)
				q3++;
		default:
			q4++;
			break;
		}

	
	}
	
	cout<<"max is"<<max<<endl;
	cout<<"min is"<<min<<endl;
	cout<<"Total number of even is "<<even<<endl;
	cout<<"Total number of odd is "<<odd<<endl;
	cout<<"Numbers that have remainders of 0"<<endl;
	cout<<q0<<endl;
	cout<<"Numbers that have remainders of 1"<<endl;
	cout<<q1<<endl;
	cout<<"Numbers that have remainders of 2"<<endl;
	cout<<q2<<endl;
	cout<<"Numbers that have remainders of 3"<<endl;
	cout<<q3<<endl;
	cout<<"Numbers that have remainders of others"<<endl;
	cout<<q4<<endl;
	
	
	getch();
	cin.get();
}

Last edited on
Yes try that.
Topic archived. No new replies allowed.