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);   
}
Grn Xtrm commented: Good first post. +1
VernonDozier commented: Used code tags on first post. +8

Recommended Answers

All 2 Replies

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.

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 :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.