Hi folks,
So I made this program to convert bits to bytes, because I'm so sick of seeing ISP's advertise speeds in megabits, which I consider an intentional attempt to decieve :P And I think I've finally understood how the return value of scanf works since the last time I posted here, so my program can check to see if an integer was entered before processing the input, but I'm stuck on how to make the whole program start over if an integer is not entered. I have a hunch it would involve a loop, but I can't figure out how to make the program start over at "How many mb do you need converted?" if an integer is not entered into scanf... Any ideas?
Here is the code I have so far:
Code:
#include <stdio.h>
int main () {
int b, mb, kb, Byte, kB, mB, gB;
char term;
printf ( "\nHow many mb do you need converted? " );
if ( scanf ( "%d%c", &mb, &term ) != 2 || term != '\n' ) {
printf ( "\nThis program requires you enter an integer." );
printf ( "\n" );
}
else {
printf ( "\n" );
kb = mb * 1024;
b = kb * 1024;
Byte = b / 8;
kB = Byte / 1024;
mB = kB / 1024;
gB = mb / 1024;
if ( kB < 1024 ) {
printf ( "%i mbps is %i kBps\n", mb, kB );
}
else {
printf ( "%i mbps is %i mBps\n", mb, mB );
}
}
printf ( "\n" );
return 0;
}
* oh, and my program makes the assumption for now at least, that mb will be inputted because that's the unit of measurement that i usually see advertised, and i didn't bother making an if statement to print a conversion in terms of gigabytes because i've never heard of a connection that fast :P