Sunday, July 26, 2009

Writing a C program...HELP!!!?

I dont kno where to begin writing this program.





The program should ask a user which type of violation they have, which will be either A, B, C or D. Each user will have every type of violation. After asking for a type of violation, the program will ask the user how many violations of that type they have. Lastly, the program will display the total fine for that person.





VIOLATION TYPE and FINE


A $30.00


B $90.00


C $120.00


D $290.00





How do I begin?





This is what I have so far....





#include %26lt;stdio.h%26gt;





void main()


{





what's next?

Writing a C program...HELP!!!?
You've already begun... you have the beginning of the main() function.





Now decide what kind of information you're going to obtain from the person entering the data and what kind of data you'll calculate when the program is running. Each item will be stored in a variable. You need to name them and define what kind of data that is.





For example, you said they will enter a violation and it will be a letter. So, what kind of variable can hold letters? int, long, float? No, those are for numbers only. You also need to give it a name. Hmmm... violationType is a good name.





You say that it must ask for each violation and the number of violations for each. So for now, let's just do the following for each violation:





What commands are used to "get" data from the user? You need to do that, but you also need to tell them what your looking for. So print out a "prompt" and then get the data.





After getting the data, make sure it's valid. If not (for now) just display a message saying it's bad and exit the program.





If good, as for the number of violations for that type. You need to store this in a variable.





Do the above for the other three violations. (You can change this later on to a more managable approach.)





Once you get the info for all four violations, then you need to calculate the total. This is simple math but the result is going to go into a variable. Print out the result and your done.





If you get all of this done and have problems, post your code and ask for help. People here will gladly help.
Reply:You're kidding!! Look up the syntax.





You just explained the entire thing.





*The program should ask a user which type of violation they have.


--So ask and get the answer into a variable.


*After asking for a type of violation, the program will ask the user how many violations of that type they have.


--So ask and get the answer into a variable.


Lastly, the program will display the total fine for that person.


--Multiply and Output the answer.


You didn't want the actual code right??


No comments:

Post a Comment