Solved.

Solved.
Last edited on
hmm convert the int to string then check it ,, or use mod and divide


1
2
3
4
5
6
7
bool doubleDigits( int input ){
    while( input >= 10 ){
        if( input % 10 == input / 10 % 10 ) return true;
        input /= 10;
    }
    return false;
}


mod and divide is not a big hassle if you only compare 2 digit at a time
but it can become trouble some when dealing with 3 or more digits at once
so converting them to string would be much easier to do if you compare multiple digits at once

I found it a little bit strange to use class for this kind of work,,,
but if that's your preferences then I cannot say anything that would change it
Solved.
Last edited on
You need to go back to your textbooks and read up on how to do if statements and blocks. If you want your if statement to control the execution of multiple statements, you need to enclose those statements in curly braces.
Are you sure you are ready for class in C++ ???
I still think that the procedural type of programming should be mastered before moving to class,,,
because it's the easier to do that than class at least for me...

class does simplified things if you're doing a project ...
but it doesn't help much if it's just a small simple program


anyway you should put the output the code in printPhoneNumberStats instead of changing the code I gave you

1
2
3
4
5
6
7
8
9
10
11
12
13
14
void printPhoneNumberStats(ostream& out) const 
{
	out<<"Printing phone number information:\n";
	out<<" Country code: "<<countryCode<<endl;
	out<<" Area code:    "<<areaCode<<endl;
	out<<" Phone number: "<<number<<endl;
	out<<" Type:         "<<type<<endl;
	out<<" Year:         "<<year<<endl;
        if( doubleDigits() ) cout << "There is a double digits .... " << endl;
	out<<endl;

	system("pause");
	out<< "\n";
}


and also you are not using your outputs parameter correctly change cout to out because your outputting to stream rather than a cout which is also a stream

I mean that there is multiple type of stream cout is just one of them...

I might be using all the wrong term but you should get the point...
do you get it ?
Solved.
Last edited on
Solved.
Last edited on
Solved.
Last edited on
sigh*, I don't think you are good enough in procedural type of programming yet ,,,
but if your prof said so then I can't say anything to change that

doubleDigits takes an argument / parameter
please don't take my code so literally that you copied everything I throw anything I throw at you without knowing what the code does

so it should input the number you want to process

for example
1
2
if( doubleDigits (44203203) ){
}


but for your case , I don't know which variable stores the phone number
I am guess "number"

so it should be
1
2
3
if( doubleDigits (number) ){
}


and also
some hint if you haven't realized it

online compiler doesn't allow you to include non standard library such as
#include "stdafx.h"


or for you to use system
Thanks again, I somehow overlooked the number variable in the input.
Topic archived. No new replies allowed.