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.
#include <iostream>
#include <conio.h>
usingnamespace 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|
#include <iostream>
#include <conio.h>
usingnamespace 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();
}