If-then-else


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting If-then-else
# 1  
Old 04-18-2011
If-then-else

Dear experts,

Here is a small description of my problem.

Every 30s call is charged 200 cents.

e.g 1. if customer A makes a 90s call, he shud be charged 600 cents
2. If customer makes a 240s call, he shud be charged 1600 cents

The maximum seconds the call can last is 5400 s which is 90 minutes and maximum charge of 36000 cents

How can i put this in a simplest format using if then else, instead of putting it in 180 loops?

Pls help.
# 2  
Old 04-18-2011
You might want to explain a bit more about your problem. I can't see how an if-then-else is applicable here, nor why you need 180 loops. It's a simple multiplication, unless there's (strange) stuff going on around it.
# 3  
Old 04-18-2011
The only thing you check with if/then/fi would be if the max for seconds or cash has been hit. The rest is just some maths, as Pludi said.

Example:

Code:
#!/bin/bash

MAX=5400
PRICE=200
UNIT=30

echo "Enter seconds:"
while read USED; do
    if (( $USED < 5400 )); then
        echo "You're inside the limit; pay me $(($USED*$PRICE/$UNIT)) cents!"
    else
        echo "Hey, you're out of bounds!"
    fi
done

exit 0

Output:
Code:
Enter seconds:
90
You're inside the limit; pay me 600 cents!
6000
Hey, you're out of bounds!

# 4  
Old 04-20-2011
Hi Zaxxon,

Thanks. Sorry for being very brief in my description. Here is more details.

Actually the calculation is already by a system and output files are generated in a file.

e.g
Code:
customerA|time in s|amount
custA|60|400


What i have to do is, grep this scenarios and dump them in a file. This is for a particular type of call, say an international call.

for national call, the rates for 30s maybe in multiples of 50 cents each time.

I have to capture the international calls by this conditions and dump them to a file.

pls help.

Last edited by zaxxon; 04-20-2011 at 05:06 AM.. Reason: code tags, restructuring example
# 5  
Old 04-20-2011
If I understood it correct, you have a file with plenty of these:

Code:
custA|60|400
...

And you just want to have those, that have a higher value in one of the fields, like let's say the > 400:

Code:
awk -F"|" '$3 > 400' infile

That will print all lines in file "infile" where the field 3 is higher than 400.
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question