HERES THE CODE:

#include <iostream>
#include <conio.h>
using namespace std;
int main() {
 int a,b,c,d;

 cout << "Enter Four Digit positive number: ";
 a = getch();
 cout << char(a);
 b = getch();
 cout << char(b);
 c = getch();
 cout << char(c);
 d = getch();
 cout << char(d);

 cout << "\nOutput:\n";
 cout << char(a) << "\n";
 cout << char(b) << "\n";
 cout << char(c) << "\n";
 cout << char(d) << "\n";

 getch();
 return 0;
}

Thanks!

Edited 5 Years Ago by Nick Evan: Added CODE-tags

Well i know a little but one time that they give a laboratory exercise.. i can't get it.. can you help me displaying the program in vertical..

HERE'S THE PROBLEM:

Write a program that prompt the user to input four-digit positive integer. The Program then outputs the digits of the number, one digit per line.

FOR EXAMPLE:

if input is 3245,
the output is:
3
2
4
5

Well i have a program for that but it only displays in horizontal when i compile & run the program in TURBO C++.

HERES MY PROGRAM:

HERE is C CODE

#include <stdio.h>

int main()
{
int a;
clrscr();

printf("Enter four-digit integers:\n");
scanf("%d" &a); //THIS IS MY PROBLEM!
printf("\nThe numbers are:%d\n%d\n%d\n%d", a);

getch();
return 0;
}

MY OUPUT:

Enter four-digit integers:
The numbers are: >> THE OUTPUT BUT STILL IN HORIZONTAL!!


That's my PROGRAM BUT I NEED SOME HELP! ABOUT THIS RUNNING THE PROGRAM IN VERTICAL..

THANK YOU!

Edited 5 Years Ago by Nick Evan: Added CODE-tags (again). Also stop typing in ALL CAPS. It's considered SHOUTING and VERY RUDE

There's NO NEED TO TYPE IN CAPS. We can hear you just fine. If you are working in C, this should probably be moved over there. I'll flag it for a mod.

Edited 5 Years Ago by jonsca: n/a

So what does your homework asignment have to do with converting cout to printf()?

You will need to extract each digit of the number and then print only that digit. The mod operator % and divide / will help you do that. The mod operator returns the remainder after division, so if the number is 1234 then 1234 % 10 will give you the 4. Next divide 1234 by 10 to make the number ready to retrieve the nedxt digit -- 3. Repeat that process in a loop until all digits have been extracted and printed.

Edited 5 Years Ago by Ancient Dragon: n/a

im sorry im a new here but ill try... thanks for the tip!
and by he way thank you Ancient Dragon. for nice idea you share..

This article has been dead for over six months. Start a new discussion instead.