Well, there are a number of ways you could solve this problem.should i use "if... else....." to solve it?
My point was not to take it what I wrote as a direct translation, but to think about the problem and how you would solve it.
If you believe you could do it using an if..else statements then go ahead and try it out and see what you come up with. After that think of ways to improve your program or how you could write it using a different approach.
The best way to learn programing is by actually doing it, and I'm sure you've heard this/will hear this a lot of times.
So write some code and see where you get with it.
The very basic fundamentals for a programmer is to be able to code logic! This usually means that the programmer can translate flow charts and pseudo code into real code.
This is a part we cannot help you with! This is the part that YOU must fully understand in order to program any sort of program.
But it's not difficult. All that is required is that you think about how something is done and that you know about these control statements in the language.
Do you know about loops and if statements? They control the logic of the program.
thanks guys.. i'd try already.. but, got some errors...
can u guys help me.. just state wut is wrong..
i'll try to figure out myself, coz i wanna learn it.. =)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Code:#include <stdio.h> int main () { float average, fahrenheit, Celcius, total; int counter; total = 0; counter = 0; do { printf("Enter temperature readings in Fahrenheit (999 to end): "); scanf("%f", &fahrenheit); counter = counter + 1; Celcius = (fahrenheit-32) * 5/9; printf("\n%d.Fahrenheit\tCelsius\n", counter); printf("%.2f\t\t%.2f\n\n", fahrenheit, Celcius); }while (fahrenheit != 999); if (counter != 0) { total = total + Celcius; average = total / counter; printf("Average is %.2f Celcius\n", average); } else printf("No reading is entered.\n"); return 0; }
i want the output to be like this:
Enter temperature readings in Fahrenheit (999 to end): 88 77 80 999
1. Fahrenheit-------Celcius
88-------------------30.89
2.Fahrenheit--------Celcius \*please ignore "-----------" i just want to make the output*\
77--------------------24.77
3.Fahrenheit--------Celcius
80--------------------26.67
Average 41.65 Celcius
Last edited by naspek; 07-22-2009 at 06:32 PM.
but, my 'else" isnt workin...Code:#include <stdio.h> int main () { float average, fahrenheit, Celcius, total; int counter; total = 0; counter = 0; printf("Enter temperature readings in Fahrenheit (999 to end): "); scanf("%f", &fahrenheit); while (fahrenheit != 999) { Celcius = (fahrenheit-32) * 5/9; total = total + Celcius; counter = counter + 1; printf("\n%d.Fahrenheit\tCelsius\n", counter); printf("%.2f\t\t%.2f\n\n", fahrenheit, Celcius); scanf("%f", &fahrenheit); } if (counter != 0) { average = total / counter; printf("Average is %.2f Celcius\n", average); } else printf("No reading is entered.\n"); return 0; }
how can i fix it?
You have no if, let alone an else, inside your while loop.