So I've decided to add some programming skills to my repertoire, typically i've been an application support analyst with beginner to average SQL coding skills, but in today's climate I know I need to get better at automating simple tasks. So I bought a course in c programming (this is not for college credit, so by asking I'm not cheating). So far it's going quite well, but I've come against a problem, actually I decided to improve upon the challenge given to me and I can't seem to figure it out. Originally I was asked to create a small application that printed out the width, height, perimeter and area of a rectangle, with the width and the height hard-coded. That was simple to figure out. I decided to add an extra challenge and have the end user input the width and height of rectangle, but it's not working like I planned. I'm including my code and as well my output after compiling. I don't really want an answer as I would like to discover the solution myself, but if someone could point me to some documentation that would be much appreciated.
CODE:
#include <stdio.h>
#include <stdlib.h>
int main()
{
double width;
double height;
double perimeter;
double area;
char newLine = '\n';
printf("Please enter the width of your rectangle:");
scanf("%f", &width);
printf("Please enter the height of your rectangle:");
scanf("%f", &height);
perimeter = 2.0 * (height + width);
area = (width * height);
printf("%c",newLine);
printf("The widith of the Rectangle is: %.2f centimeters %c",width, newLine);
printf("The height of the rectangle is: %.2f centimeters %c",height, newLine);
printf("The permimeter of the rectangle is: %.2f centimeters %c",perimeter, newLine);
printf("The area of the rectangle is: %.2f centimeters %c",area, newLine);
printf("%c",newLine);
return 0;
}
OUTPUT:
[user@localhost.local]$ ./output/rectangle.a
Please enter the width of your rectangle:15
Please enter the height of your rectangle:12
The widith of the Rectangle is: 0.00 centimeters
The height of the rectangle is: 0.00 centimeters
The permimeter of the rectangle is: 0.00 centimeters
The area of the rectangle is: 0.00 centimeters