I recently (three days ago) began coding in c and i cannot understand why the final scanf is breaking my code.
I checked the syntax and from what i can tell it is correct. I revised the final segment to multiply integers instead of doubles, and it worked. I revised the final segment to multiply floats instead of doubles, and it broke.
int main()
{
// add two numbers
int addOne,addTwo,sumOne;
printf("Please enter two integers: ");
scanf("%d %d",&addOne,&addTwo);
sumOne = addOne + addTwo;
printf("The sum of these two numbers is: %d\n",sumOne);
// above code works.
// multiply two decimals
double decOne,decTwo,mulOne;
printf("Please enter two decimals: ");
scanf("%1f %1f",&decOne,&decTwo);
mulOne = decOne*decTwo;
printf("the multiplication of the two decimals entered is: %1f \n", mulOne);
return 0;
}
I expect to be able to intput two decimals and see the product. Instead i can only enter one and it prints out:
Please enter two decimals: 1.2 the multiplication of the two decimals entered is: 241638106882447.190000