-2

So here is my program. It is suposed to write out square of some intiger.

#include <stdio.h>

int main (){
     int a;
     printf("Type an intiger.");
     scanf("%i", &a);
     printf("Square of that intiger is %i", a*a);
     return 0;
}

When i run a program in Eclipse it first requires me to input a number.I put in 5. And then as output it gives me

Type an intiger.Square of that intiger is 25.

It should first print "Type an intiger" and then the rest. But it just combines two printf commands. What is the problem?

GovernmentFX
  • 307
  • 1
  • 2
  • 5
  • it should be "integer" – Peter Miehle Nov 25 '13 at 10:30
  • using the latest eclipse C/C++ version that I've just downloaded, a copy-paste of your code works just as one'd expect it to. Perhaps [download it here](http://www.eclipse.org/downloads/packages/eclipse-ide-cc-developers/keplersr1), and then try again. – Elias Van Ootegem Nov 25 '13 at 10:56
  • i have found an answer here: http://stackoverflow.com/questions/16877264/eclipse-c-c-printf-before-scanf-issue Thanks anyway. – GovernmentFX Nov 25 '13 at 12:06

4 Answers4

3

You need a newline character - printf("Type an intiger.\n");

In computing, a newline, also known as a line break or end-of-line (EOL) marker, or simply break, is a special character or sequence of characters signifying the end of a line of text.

Also format specifier for integer is %d

 scanf("%d", &a);
 printf("Square of that intiger is %d", a*a);
Sadique
  • 22,572
  • 7
  • 65
  • 91
  • No problem is that i want my programm to do following: "Type an intiger" 5 "Square of that number is 25" But right now i have that i type in 5 and then it combines into one single output "Type an intiger.Square of that number is 25" – GovernmentFX Nov 25 '13 at 10:29
2

If you want it on separate lines you can always add '\n' to the string to get a new line.

#include <stdio.h>

int main (){
     int a;
     printf("Type an intiger.\n");
     scanf("%i", &a);
     printf("Square of that intiger is %i", a*a);
     return 0;
}
  • No problem is that i want my programm to do following: "Type an intiger" 5 "Square of that number is 25" But right now i have that i type in 5 and then it combines into one single output "Type an intiger.Square of that number is 25" – GovernmentFX Nov 25 '13 at 10:28
2

There is 2 problem in it. First, if you input the integer, it should be %d. Example :

scanf("%d", &a);

The second, after the input, you should print \n. So, it will be like this printf("\n");. Take a look at my code :

#include <stdio.h>

int main (){
    int a;
    printf("Type an intiger.");
    scanf("%d", &a);
    printf("\nSquare of that intiger is %d", a*a);
    return 0;
}
david
  • 3,225
  • 9
  • 30
  • 43
  • 1
    No problem is that i want my programm to do following: "Type an intiger" 5 "Square of that number is 25" But right now i have that i type in 5 and then it combines into one single output "Type an intiger.Square of that number is 25" – GovernmentFX Nov 25 '13 at 10:24
0

In code::blocks it compiles fine anyway put a \n at the end of the first printf and change %i with %d

Lorenz
  • 3
  • 1