Problem Help - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Problem Help

K20J03KK20J03K Posts: 24Member
Hi everyone, I'm very new to programming in C. I'm doing my 4th homework assignment and having a bit of trouble. I was hopeing that someone here could lend me a hand.

The problem from the book is as follows:

The National Earthquake Information Center has asked you to write a program implementing the following decision table to characterize an earthquake based on its Richter scale number.

[b]Richter scale number \Characterization[/b]
n<5.0 \Little or no damage
5.0<=n<5.5 \Some Damage
5.5<=n<6.5 \Serious Damage
6.5<=n<7.5 \Disaster
n>7.5 //Catastrophe

[img=] This is a link to the code I have. I'm using Cygwin so I do not know how I would be able to copy the code out of the program. Any help would be very much appreciated.


  • ActorActor Posts: 438Member
    C is case sensitive. [b]Printf[/b] is not the same as [b]printf[/b]. When you call [b]Printf[/b] on line 14 the compiler does not know what you are talking about. Correct that and the program should run.

    However, the test [b]if (richter >= 5.0)[/b] is superfluous. Since the previous test [b]if (richter < 5.0)[/b] has already failed, other wise we would no be making this test, the test will always be true. Consider writing the tests this way:
    if (richter < 5.0)
    printf("Little or no damage") ;
    else if (richter < 5.5)
    printf("Some damage") ;
    else if (richter < 6.5)
    printf("Serious damage") ;
    else if (richter < 7.5)
    printf("Disaster") ;
    else /* no need to test */)
    printf("Catastrophe") ;
  • K20J03KK20J03K Posts: 24Member
    Aha! Redundancy and a typo.

    I'll get this code thing sooner or later. This is a good thing to watch for in my upcoming programs.

    Thank you very much.
Sign In or Register to comment.