help having input and output displayed on same line

Write your question here.
Hello, I am working on a hw assignment where I need to convert a phone number with a phrase into all numbers. I have the program running properly, the only thing is the way my professor wants it displayed. He wants it to have input and output displayed on same line, tabbed away from each other.
for example, 800-mattres would be 800-628-8737. when I run the program, they are displayed on 2 separate lines such as
800-mattres
800-628-8737

can anyone help me with a way to get them to be displayed on same line like this
800-mattres 800-628-8737?

thanks in advanced


[code]
Put the code
#include <iostream>
using namespace std;

int main() {

int counter;
int AreaCode;
char phoneNumber{};

cout << "Enter a Phone number: Area code and Phrase seperated by a '-' " << endl;
cout << endl << endl;
cin >> AreaCode;
cout << "\t" << "\t" << AreaCode;

for (counter=0; counter >= 0 && counter < 8; counter++)
{
cin >> phoneNumber;

if (counter == 0)
cout << "-";
if (counter == 4)
cout << "-";
if (phoneNumber >= 'A' && phoneNumber <= 'Z' || phoneNumber >= 'a' && phoneNumber <= 'z')
switch (phoneNumber)
{

case 'A':
case 'a':
case 'B':
case 'b':
case 'C':
case 'c':
cout << 2;
break;
case 'D':
case 'd':
case 'E':
case 'e':
case 'F':
case 'f':
cout << 3;
break;
case 'G':
case 'g':
case 'H':
case 'h':
case 'I':
case 'i':
cout << 4;
break;
case 'J':
case 'j':
case 'K':
case 'k':
case 'L':
case 'l':
cout << 5;
break;
case 'M':
case 'm':
case 'N':
case 'n':
case 'O':
case 'o':
cout << 6;
break;
case 'P':
case 'p':
case 'Q':
case 'q':
case 'R':
case 'r':
case 'S':
case 's':
cout << 7;
break;

case 'T':
case 't':
case 'U':
case 'u':
case 'V':
case 'v':
cout << 8;
break;
case 'W':
case 'w':
case 'X':
case 'x':
case 'Y':
case 'y':
case 'Z':
case 'z':
cout << 9;
default:
break;
system("Pause");

}
}
cout << endl << endl;
return 0;
}
If you edited your post and added "[/code]" to the end of your post, it would be properly formatted.

So you want the user-provided input, and then the output to be on the same line.

Are you sure you're understanding the professor's request correctly? Do you have the exact wording in text? Such things are hardly the point of beginner-level programming classes, or any classes really. When you type something in, pressing enter is how you send the information to the program, which causes a new line to printed as well.

To avoid this would require platform-specific "hacks" for console/terminal manipulation.
Last edited on
yea I am sure thats what the professor wants. when he was going over the assignment, he showed the class and showed how he doesnt want it. When I asked him again in class, I had my output open and showed him how it was. he just told me to use \t and it should put them on the same line of output by tabbing them apart.

below is the example of the output options he wants.

Sample input: Sample Output:

800-MATTRESS 800-628-8737 (leave off the last ā€œSā€)
800-mattress 800-628-8737 (leave off the last ā€œSā€)

b. Another acceptable form of output:
Sample input: Sample Output:
8 8
0 0
0 0
M 6
A 2
T 8
T 8
R 7
E 3
S 7
http://www.cplusplus.com/forum/beginner/23421/#msg122590
Read this post by Duthomhas. If you really want to go through this with, he goes through the gory details.
that does look like a lot, and more advanced than the point we are at in class. maybe I shouldn't try. I do want to be able to get a good grade, but I don't want to use any code that I can not explain. Hopefully, I misunderstood him. Thank you for you're help
Topic archived. No new replies allowed.