1. ## Homework Question...

I'm trying to display a result on the same line as the user inputs the data. How do I do this? Everytime I try to do this, it displays on the next line.

Example:

I get this:
Code:
Input Code      10 Digit Sum    Numeric         Validated
Code Value   Code

1234567890
270            12          3456789075p
I want this:
Code:
Input Code      10 Digit Sum    Numeric         Validated
Code Value    Code Value

1234567890     270                12                  3456789075p
here is my code:
Code:
//Lab assignment 1b-b
//produces a validation letter for a 10 digit #

#include <stdio.h>
#include <conio.h>

void main(void)
{
int pair1, pair2, pair3, pair4, pair5, total, vchar;

printf("Input Code	10 Digit Sum	Numeric		Validated\n");
printf("		    Code Value	    Code Value  Code\n\n");

scanf("%2d%2d%2d%2d%2d", &pair1, &pair2, &pair3, &pair4, &pair5);
total=(pair1+pair2+pair3+pair4+pair5);
vchar=total%26+65;
printf("%8d%10d%10d%12d%2d%2d%2d%2d%c",total,vchar-65,pair1,pair2,pair3,pair4,pair5,vchar);

fflush(stdin);
getchar();
}

2. Ooooooooh, I see what you mean now. Sorry, you can't portably fix it. Input in C is line based, which means you need to hit enter for any input to be sent to the program. Because of this that newline will be printed before you can do anything about it. Try this and see if you can tolerate it:
Code:
#include <stdio.h>

int main(void)
{
int pair1, pair2, pair3, pair4, pair5, total, vchar;

scanf("%2d%2d%2d%2d%2d", &pair1, &pair2, &pair3, &pair4, &pair5);

total=(pair1+pair2+pair3+pair4+pair5);
vchar=total%26+65;

printf("Input Code	10 Digit Sum	Numeric		Validated\n");
printf("		    Code Value	    Code Value  Code\n\n");
printf("%2d%2d%2d%2d%2d", pair1, pair2, pair3, pair4, pair5);
printf("%8d%10d%10d%12d%2d%2d%2d%2d%c\n",total,vchar-65,pair1,pair2,pair3,pair4,pair5,vchar);

getchar();

return 0;
}

3. ## it is supposed to be looped...

Is there any way of doing that? How about in C++ if C can't handle it.

4. >Is there any way of doing that?
...Yes, but I don't recommend it. And it pains me to know in my heart that you're going to rejoice when you see it work like you want and that you're going to use it. And it pains me even more to know that you'll continue to use it when you don't need to despite portable options:
Code:
#include <stdio.h>
#include <conio.h>

int main(void)
{
int pair1, pair2, pair3, pair4, pair5, total, vchar;

printf("Input Code	10 Digit Sum	Numeric		Validated\n");
printf("		    Code Value	    Code Value  Code\n\n");

cscanf("%2d%2d%2d%2d%2d", &pair1, &pair2, &pair3, &pair4, &pair5);

total=(pair1+pair2+pair3+pair4+pair5);
vchar=total%26+65;

printf("%8d%10d%10d%12d%2d%2d%2d%2d%c\n",total,vchar-65,pair1,pair2,pair3,pair4,pair5,vchar);

getchar();

return 0;
}
>How about in C++ if C can't handle it.
C++ would suffer the same problem, and have the same non-portable solution.

5. ## Yes it woks!

Why does it pain you? And what does more "portable options" mean? I'm new to programing but I want to be a good programmer.

6. >Why does it pain you?
I'm very anal about writing code that conforms to the C standard. Introducing a non-standard header and function for some frivolous formatting chafes.

>And what does more "portable options" mean?
It generally means compromising nifty features for the ability to compile your code on any machine with a C compiler and have it work properly.

7. It is my sworn duity (because I swear a lot), to damn you for your post! And so I shall!
Code:
void main(void)
Go read this FAQ entry now!
Code:
fflush(stdin);
When you're finished, go read this FAQ entry!

Heed my words, neophyte, lest you be haunted by the ghosts of coders past, and posters present! (Mainly posters present, like myself!)

Quzah.

8. > And what does more "portable options" mean?
It also means you don't have to learn (and relearn and relearn and ....) a whole bunch of stuff each time you upgrade or change your compiler.