What is wrong with my coding?

I'm using Visual Studio 2005 and need to write a program that allows you to input a number then receive a response based on the number you input.  If I typed in 5.3, I should receive a response "rating causes some damage."  Unfortunately, this is not the case.  Help!!
/* Earthquake based on the Richter Scale Characterizations */
#include<stdio.h>
int
main(void)
{
	double n;	/* represents number registered */
	printf("Type the number registered on the Richter scale and press return> ");
	scanf("%f", &n);
 
if (n < 5.0)
	printf("%f causes little or no damage.\n", n);
else if (5.0 <= n < 5.5)
	printf("%f rating causes some damage.\n", n);
else if (5.5 <= n < 6.5)
	printf("%f rating does serious damage: walls may crack or fall.\n", n);
else if (6.5 <= n < 7.5)
	printf("%f disastrous results: houses and buildings may collapse.\n", n);
else
	printf("%f Catastrophic: most buildings are destroyed.\n", n);
 
return (0);
}

Open in new window

Noo2thisAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pratima PharandeCommented:
try this
#include<stdio.h>
int
main(void)
{
	double n;	/* represents number registered */
	printf("Type the number registered on the Richter scale and press return> ");
	scanf("%f", &n);
 
if (n < 5.0)
	printf("%f causes little or no damage.\n", n);
else if ((5.0 <= n) && (n < 5.5))
	printf("%f rating causes some damage.\n", n);
else if ((5.5 <= n) && (n < 6.5))
	printf("%f rating does serious damage: walls may crack or fall.\n", n);
else if ((6.5 <= n) && (n < 7.5))
	printf("%f disastrous results: houses and buildings may collapse.\n", n);
else
	printf("%f Catastrophic: most buildings are destroyed.\n", n);
 
return (0);
}

Open in new window

0
mgonulluCommented:
Why not use cin and cout instead?
0
mgonulluCommented:
By the way I found another solution using scanf and printf
change double n to float and it will works
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

mgonulluCommented:

#include <stdio.h>
#include "conio.h"
int
main(void)
{
       float n=0;       /* represents number registered */
        printf("Type the number registered on the Richter scale and press return> ");
      //  scanf("%f", &n);
		scanf("%f",&n);
		printf("You entered : %f\n",n);
 
if (n < 5.0)
        printf("%f causes little or no damage.\n", n);
else if (5.0 <= n && n < 5.5)
        printf("%f rating causes some damage.\n", n);
else if (5.5 <= n && n< 6.5)
        printf("%f rating does serious damage: walls may crack or fall.\n", n);
else if (6.5 <= n && n< 7.5)
        printf("%f disastrous results: houses and buildings may collapse.\n", n);
else
        printf("%f Catastrophic: most buildings are destroyed.\n", n);
 _getch();
return (0);
}

Open in new window

0
Noo2thisAuthor Commented:
Pratima mcs: I already tried it the way you show, as well as the way Mgonullu shows it.  It still did not work.
Mgonullu: float, cin, getch, cout, and conio.h are not approved options for me to use.  
Will this work with nested statements or do you think switch statements will work instead?
0
mgonulluCommented:
Man remove the conio,
and remove the _getch()
in my code I used scanf and printf again, please reread my snippet
My code worked fine,
you cannot use switch case here as there are comparisons going on, the nested if works fine
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Noo2thisAuthor Commented:
mgonullu.  My bad, I didn't see the extra scanf & printf.  Nor did I observe the "float n=0".  Can you tell me why double did not work and why did float need to equal 0?
0
Noo2thisAuthor Commented:
Mgonullu,
Can you tell me why double did not work and why did float need to equal 0?  If I'm using real numbers, why doesn't double work?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.