Results 1 to 3 of 3
Hello all, something really astounding happened!
...........
Thursday........
Jun 19th,
...........
nearly midnight
............
My C program worked!
It was an exercise question in a C book. To make a ...
- 06-20-2008 #1Linux User
- Join Date
- Jun 2007
- Posts
- 458
My C Programs Begin to Work!
Hello all, something really astounding happened!
...........
Thursday........
Jun 19th,
...........
nearly midnight
............
My C program worked!
It was an exercise question in a C book. To make a calculator that works wit these:
<number><space><sign>
The signs can do these:
S: set the value of the accumulator
/: divide accumulator by number specified
x: multiply accumulator by number
+: you know what
-: //ditto
0 E would end the program:
Now is the return statement correct in last case i.e. E? How to use break there?Code:#include <stdio.h> int main () { float value, number; char sign; int tmp; printf("Begin Calculations\n"); for ( tmp = 0; ++tmp; tmp > 0 ) { scanf("%f %c", &number, &sign); switch ( sign ) { case 'S': { value = number; printf("= %f\n", value); break; } case '+': { value += number; printf("= %f\n", value); break; } case '-': { value -= number; printf("= %f\n", value); break; } case 'x': { value *= number; printf("= %f\n", value); break; } case '/': { value /= number; printf("= %f\n", value); break; } case 'E': { printf("= %f\n", value); printf("End of Calculations\n"); return 0; } } } return 0; }"When you have nothing to say, say nothing."
- 06-20-2008 #2Linux Newbie
- Join Date
- Nov 2007
- Location
- Planet Earth
- Posts
- 152
Break is optional... in this case is not necessary because of return statement.
Congrats... I remembered my first C program too... oh old good times hehehe...
HugoEOF
- 06-20-2008 #3
It's not just a C thing. The first program I ever wrote was in basic; it converted centigrade to fahrenheit and backwards. And when I ran it and it actually worked, I knew how God felt on the seventh day. It was that sense of omnipotence: I had told a computer what to do and the computer had actually done it!
"I'm just a little old lady; don't try to dazzle me with jargon!"


Reply With Quote
