2

Hi ive been experimenting with basic calculations and using scanf to be able to enter an integer, if i give numb_1 a value it will divide and calculate the remainder fine but i cant get it to work by being able to enter a number, it just sits on the command screen doing nothing.
Sorry for the noobish question im probably doing something clumsy but ive searched quite awhile and can't figure it out!

#include "stdafx.h"

#include <stdio.h>

   
int main ()
{
          
    int numb_1, numb_2 = 5, result,remainder;  

    //ask user to enter integer
	printf ("Please enter number to be divided by 5:\n");
	scanf("%d\n",&numb_1);

	//calculation
        result = numb_1 / numb_2;              
        remainder = numb_1 % numb_2;  

	//produce output
    printf ("Divided by 5 is %d with remainder %d\n\n", result,remainder); 

          
    return(0);   
}
Votes + Comments
Used code tags on first post.
Good first post.
2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Nitricity
0

Remove the "\n" from line 13. It worked for me this way.
\n sends output to the next line. When you are scanning input, you don't need to go to a new line.

By the way, next time you have a C question dont post it in the C++ forum. We have a forum dedicated to C. Thanks.

Edited by Grn Xtrm: n/a

1

As simple as that.. cheers for pointing that out.
Apologies on posting in the wrong section also, i noticed after post but couldnt find a way to delete it, wont happen again :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.