Reputation: 1
i know that int and char cant be specified by different data types and char basically represents the ASCII values. what confuses me is storing them in the SAME data type which can be used later on. For example, if i were to input int and char both type of data from the user in variable x, how would i define the variable? like with what type of it? lets say you were to input integers from the user and when the user enters a symbol('='), the program ends.
void main()
{
int count, flag = 0;
int i = 0;
int x = 0;
const int ASCII_VALUE_OF_EQ = '='
x = ASCII_VALUE_OF_EQ;
for (i = 0; i <=10; i++){
cout << "Enter the number = ";
cin >> x;
if (x == ASCII_VALUE_OF_EQ)
break;
}
//to find if the number before '=' was prime
int m = 2; int c = 0;
while (m < x)
{
if (x%m == 0){
c++;
break;
}
m++;
}
if (c == 0){
cout << x << " is a Prime number"<<endl<<"here are all the prime numbers that come before '='" << endl;
for (int a = 2; a <= x; a++)
{
int c = 0;
for (int b = 1; b <= a; b++)
{
if (a%b == 0)
c++;
}
if (c == 2){
cout << a << endl;
continue;
}
}
}
getch();
}
Upvotes: 0
Views: 2992