hi. im trying to make a loop that will end when the user types in 8 numbers for the telephone number. a function will read in the telephone number itself and the loop will call that function. the function has to send back the string either using a reference parameter or by returning a value. im not sure how to do this but this is what i have so far.
here is the main program:
1 2 3 4 5 6 7 8
int main()
{
string telephone;
for (int x = 0; x < telephone.length(); x++) {
readoriginalnumber();
}
this is the function:
1 2 3 4 5 6 7 8
string readoriginalnumber () {
string telephone;
cout<< "Enter your telephone number" << endl;
cin>> telephone;
cout<< endl << telephone << " is your original number" << endl;
return telephone;
}
When you read the input from cin, it reads the entire line. You don't need to loop through and read each character, which is what i think you are intending to do.
ok so i have found a way to use the while loop but i dont know how to make it stop after a user writes more than 14 numbers. i counted all the spaces and () and i made the number 14 instead of just numbers. and what do i print the function so that the original number is printed. right now the words print and not the numbers in front of them.
here is what i have so far:
sorry i forgot to mention that i have to make the program read in more than 6 numbers and then break them down. for example the output should look like this:
(718) 343-3243 is the original number
718 is the area code 343 is the exchange 3243 is the extension
the function that i have above prints only the number and another function breaks it down and prints the rest. im not sure how the main program will send the original telephone number back to the function that breaks them down. im using a function with three reference parameters but i dont know what to do after that.
Ah! Okay... In that case I would still suggest reading in the numbers as one string. Then parse through the string pulling out exactly what you need. For example: