Hey everyone. First post on these boards! I recently got into very basic C-programming because I'm taking a mandatory course in college for C-programming. The professor has assigned a few simple programs for us to create with the limited knowledge of C-programming that we have so far. Anyways, on to what brought me here...
I've had a couple minor problems with a couple of the programs he's assigned. The first one here, all the code looks perfect. It looks like it should run perfectly. But then when I run it, it asks for the first input, waits to take it in (and takes it in), waits for the second input, then skips right over that and moves on to asking the third user input and waiting for that. What's up with that? Please look at this code and tell me what's wrong with it, because I just can't see it.
// Description: Calculates how many pictures you can store on a CD.
#define MB 1048576
#define PX 3
// Delcares necessary variables
int cd_space, pic_length, pic_width;
int pic_size, number_pics;
// Asks user for input
printf("How many megabytes of free space is on the CD? ");
printf("What is the length of each picture in pixels? ");
printf("What is the width of each picture in pixels? ");
// Calculates how many whole pictures can be placed on the CD
pic_size = pic_width * pic_length * PX;
number_pics = (cd_space * MB) / pic_size;
printf("You can store %d pictures on your CD.", number_pics);
Second program here, I'm getting different numbers in the results than my professor's practice run of the program. Can you please look at this one and tell me if all the math and everything looks correct, and it might be my professor's program that was wrong?
// Description: Calculates the number of jelly beans in a container.
#define PI 3.14159265
// Declare necessary variables
double jb_radius, conta_radius, conta_height, percent_air;
double jb_volume, conta_volume, conta_volume_noair, jb_number;
// Request user input
printf("What is the radius of a single jelly bean? ");
printf("What is the radius of the container? ");
printf("What is the height of the container? ");
printf("What percentage of the container is filled with air? ");
// Calculate volumes and number of jelly beans
conta_volume = PI * conta_radius * conta_radius * conta_height;
conta_volume_noair = conta_volume - (conta_volume * (percent_air * .01));
jb_volume = 4 / 3 * PI * jb_radius * jb_radius * jb_radius;
jb_number = conta_volume_noair / jb_volume;
// Tell user how many jelly beans are in the jar
printf("There are %.0lf jelly beans in the jar.", jb_number);
Thanks to any and everyone who helps!