If you feel like being an idiot and copying and pasting your code with some changes about 10 times, sure.
Printable View
If you feel like being an idiot and copying and pasting your code with some changes about 10 times, sure.
C is not a language to mess around with. Learn how it works before you start doing things you have no idea what you're doing.
Get a book. Read a tutorial. Anything. Just learn loops & whatever else you need to know. It's not difficult.
goto should never be needed. goto's will make the code very confusing and ugly.Quote:
can it just use if else switch goto ?
Careful about gotos, there. Gotos can indeed by a good thing in C, if you know how to use them correctly.
They do have uses, such as breaking out of multiple loops or providing a common exit path from a function.
True. I should rephrase this. goto are not needed in this situation. goto's will make the code very confusing and ugly.
Really useful in this kind of situation though:
but this is kinda stupid:Code:while(this)
while(that)
for ...
if(catastrophe)
goto error;
Code:loop:
if(foo < 100) {
foo++;
goto loop;
}
i will learn more.^^
What kempelen showed you was a basic for loop and a simple one-dimensional array. A problem, well any problem in programming usually has more than solution to it.
Considering you are fairly new to C, I would use the loop and forget the array ( just use a simple counter to increment each letter grade total ). When you have learnt more about program flow and arrays you will understand more about it.