Hi,
I am a newbee in C++
Please review this is what I wrote , what so ever I understood so far,
My question is that I have to " Write a program C++ array that reads in an integer number and checks whether any of the digits in the number appear more than once"
Hint: Use an array called digits_seen of size 10 whose base type is Boolean. It will be indexed from 0 to 9, which corresponds to the 10 possible digits and initially all the entries should be set to false. When the user enters a number n, the program examines the digits and sets the appropriate index entry in the array to true. If when it goes to do this, the entry is already true then you have encountered a duplicate!
HINT2: use type long int to store the input number number read in…so you get a lot of digits.
I have just started few weeks ago so this what I know so far.. Please help
#include<iostre am>
using namespace std;
void initialize(bool digit_seen[]);
const int size=10;
int main()
{
bool digit_seen[size];
int new_value;
long int i;
initialize(digi t_seen);
cout<<"Enter integers\n";
cin>>digit_seen[0];
new_value=digit _seen[0];
for(i=0; i<size; i++)
{
if(digit_seen[i]==true)
new_value=digit _seen[i];
cin>>digit_seen[i];
}
if(digit_seen[i]!=new_value)
cout<<"no repeat\n";
else
cout<<"repeat\n ";
return 0;
}
void initialize(bool digit_seen[])
{
int i;
for (i = 0; i <10; i++)
digit_seen[i]=false;
return;
}
I am a newbee in C++
Please review this is what I wrote , what so ever I understood so far,
My question is that I have to " Write a program C++ array that reads in an integer number and checks whether any of the digits in the number appear more than once"
Hint: Use an array called digits_seen of size 10 whose base type is Boolean. It will be indexed from 0 to 9, which corresponds to the 10 possible digits and initially all the entries should be set to false. When the user enters a number n, the program examines the digits and sets the appropriate index entry in the array to true. If when it goes to do this, the entry is already true then you have encountered a duplicate!
HINT2: use type long int to store the input number number read in…so you get a lot of digits.
I have just started few weeks ago so this what I know so far.. Please help
#include<iostre am>
using namespace std;
void initialize(bool digit_seen[]);
const int size=10;
int main()
{
bool digit_seen[size];
int new_value;
long int i;
initialize(digi t_seen);
cout<<"Enter integers\n";
cin>>digit_seen[0];
new_value=digit _seen[0];
for(i=0; i<size; i++)
{
if(digit_seen[i]==true)
new_value=digit _seen[i];
cin>>digit_seen[i];
}
if(digit_seen[i]!=new_value)
cout<<"no repeat\n";
else
cout<<"repeat\n ";
return 0;
}
void initialize(bool digit_seen[])
{
int i;
for (i = 0; i <10; i++)
digit_seen[i]=false;
return;
}
Comment