Obviously, if I use my size 5's, I would need a lot more to make the 4 inches. How do I figure out how many more stitches I need to cast on to get it to the correct size?
If you want to use a tighter gauge than the one given you can do that. Make a gauge swatch with the size needles you want to use and then measure the stitches over 4 inches, 2 inches or even 1 inch and see what you are getting. If the fabric you are creating at your gauge is satisfying to you then you are ready to figure out how many stitches you need for your scarf in the new gauge.
If the pattern is very basic it is easy. Say if you are getting 24 stitches in 4 inches (that would be 12sts for 2" and 6st for 1"). Take the width you want your scarf and multiply it by the number of inches you are using to figure with. Like if you want your scarf 8 inches wide and you measured over 4" then you would multiply 24X2 because you would only need 2 groups of 4" to get your 8" width. If you measured across 2" you would multiply 12X4 because you would need 4 groups 2 inches wide (and each 2" would have 12sts) to make an 8" scarf. If you measured across 1" you would multiply 8X6 because each of the 8 inches would have 6 stitches. You would get the same answer in each case. You would need 48sts to make an 8" scarf.
If your pattern has instructions that tell you that you need a multiple of something + some number, for instance a multiple of 10+3. Then you need to figure out your gauge and how wide you want your scarf and then adjust your final number to fit those perimeters. If you wanted the 8" scarf you would need 48 stitches like we figured above. 48 divided by 10 (because you must have a multiple of 10) would be 4 tens and 8 more stitches. If you add 2 to the 8 extra you would have another 10, then you need to add 3 because it said +3. So you would need 48+2=50 (a multiple of 10) and 3 more. So you'd need 53 stitches. If that seemed too wide you could go with a 4X10=40+3 for 43sts. Your choice 43 for a little narrower scarf or 53 for a little wider one.
If your scarf has a pattern stitch with a repeat section you have to figure out how many stitches are in the repeat and how many are before and after the repeat and figure out your own multiple of +? numbers and do the same thing as above to figure out how many stitches you need. If you have a repeat but don't know how to figure out how many stitches it is over, give us the repeat and we can tell you.