How to put a double line break after scanf

0 Ash Marz · April 11, 2015
#include <stdio.h>
#include <stdlib.h>


int main()
{
int ab;
printf("Enter value for ab: \n");
scanf("%d", &ab);
int cd;
printf("Enter value for cd: \n");
scanf("%d", &cd);
int ef = ab +cd;
printf("The value for the total is %d \n \n \n", ef); 


i TRIED MNAY DIFFERENT THINGS TO CREATE A DOUBLE LINE BREAK AFTER scanf BUT I CANT... Please Help

Post a Reply

Replies

Oldest  Newest  Rating
+1 Clark Alaan · April 12, 2015
Hi Ash,

I'm not exactly sure what you're question is about, but as Franz has said, putting the line of code:
/*Double break(new line)*/
//Your scanf
printf("\n\n");
/*Or simply,*/
//Your scanf
printf("\n");

*The bottom example is done because when the user of your program enters something, they press Enter which creates a new line.

The idea is order. I believe you were trying to do a double break in the line:
printf("The value for the total is %d \n \n \n", ef);

with the \n\n\n, but you can do:
printf("\n\nThe value for the total is %d \n", ef);

Which pretty much does the same thing.

Hope I helped. :D


As an additional information,
Note that when a user presses [Enter] as they confirm their input, [Enter] itself is a character that is represented by "\n". Depending on what type of data your trying to get input for, it may matter.

I don't think you should be thinking about this for a while though. :)
0 Franz Schmidt · April 11, 2015
why you just don't do printf("\n\n"); after a scanf?
0 Ash Marz · April 12, 2015
Oh thank you very much... I didnt know I should put a printf for \n :)
  • 1

C

107,149 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator