This program is supposed to take a value then print the rounded value of that number to the nearest integer, tenth, hundredth, and thousandth. Afterwards it is supposed to ask you if you want to round another number at which point you say yes or no. I know alot of the parts in this program aren't fully working yet but what is really confusing me is the do while structure.
When it goes to say "Would you like to enter another value?" it doesn't wait for my response from scanf before going to say "I'm sorry you entered an incorrect value please enter y or no." After I enter a value it keeps on looping the same message. Everything seems to be there what am I missing?
Sorry for writing such a long question.
Code:
#include <stdio.h>
#include <math.h>
void roundNumbers( void );
void roundToInteger ( float );
void roundToTenths( float );
void roundToHundreths( float );
void roundToThousandths( float );
int main()
{
int loopcontrol;
printf("n is %d and y is %d\n", 'n', 'y');
/* -------------------------------------This is where I seem to be having the problem ---------------------------------------- */
do {
roundNumbers();
printf("Would you like to round another number(press y or n)? ");
scanf("%d", &loopcontrol);
while( loopcontrol != 'y' || loopcontrol != 'n' )
{
printf("I'm sorry you entered an incorrect value please enter y or n");
scanf("%d", &loopcontrol);
}
} while(loopcontrol == 121);
return 0;
}
void roundNumbers( void )
{
float x = 0;
printf("Enter value to be rounded: ");
scanf("%f", &x);
roundToInteger( x );
roundToTenths( x );
roundToHundreths( x );
roundToThousandths( x );
return;
}
void roundToInteger( float number )
{
float y, x;
x = number;
y = floor(x * .5);
printf("%.2f rounded to the nearest integer is %.2f\n", x, y);
return;
}
void roundToTenths( float number )
{
float y, x;
x = number;
y = floor(x * 10 + .5);
printf("%.2f rounded to the nearest tenth is %.2f\n", x, y);
return;
}
void roundToHundreths( float number )
{
float y, x;
x = number;
y = floor(x * 100 + .5);
printf("%.2f rounded to the nearest hundredth is %.2f\n", x, y);
return;
}
void roundToThousandths( float number )
{
float y, x;
x = number;
y = floor(x * 1000 + .5);
printf("%.2f rounded to the nearest thousandth is %.2f\n", x, y);
return;
}