I've only stated to work with crystal reports recently so im still learning how to create reports, the version im using is 2008

I have an orders table that looks like this
Code:
------------------------------
amount    | payment_type     |
------------------------------
10        | Cash              |
15        | Credit            |
15        | Cash              |
24        | Check             |
------------------------------
what im trying to do is create a formula that would only sum up the amounts a payment type
eg. I want the formula to give me the total for the orders that were paid by "CASH"

here is the formula im using:
Code:
Local CurrencyVar ordersCash := 0;
Local NumberVar i := 0; 

While i < {@totRecords} Do
(
if "CASH" in {DailySales.payment_type}
then 
    ordersCash :=  (ordersCash + {@amtPaidByOrder});
    i := i + 1;
);

ordersCash;
the idea is to use a while loop to go through all the rows on my query but it keeps giving me strange totals, so far i am failing to understand the logic CR is putting out, im not even sure if im using the right aproach here so if you could point me to the right direction i would really appreciate it