Howdy, Stranger!

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


Problem Help

K20J03KK20J03K Member Posts: 24
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 Member Posts: 439
    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 Member Posts: 24
    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.