Same result from two different codes

I am calculating breakeven selling price in R, i have two cases, in one case price ((p_jet, p_dsl,p_nap) is low and in another case, price (p_jet, p_dsl,p_nap) is high; everything else is same, but the R gives me the same output every time. Why is that?

This is the code for where price is high:

'''

case 1.

library(FinancialMath)
library(dplyr)
library(ggplot2)
library(plyr)
library(tidyverse)

plant info

q_fuel <- 29.88 #MLPY (million L/yr)
capex <- 214.11 #MM$ (million) capital exp (default value)
hrs <- 8406 #hr/yr

input info

q_fd <- 0.13 #M t/yr (million tonnes annually)
q_water <- 1.6 #M t/yr
q_elec <- 8.9 #M kWh/yr
q_gas <- 0.04 #M t/yr
q_h2 <- 0.007 #M t/yr
q_lab <- 55 #labor

p_fd <- 800 #/t (default value) p_water <- .57 #/t
p_elec <- 0.11 #/kWh p_gas <- .8 #/t
p_h2 <- 1210 #/t (default value) p_lab <- 0.043 #MM/labor

output info

q_jet <- 29.83 #MLPY (default value)
q_dsl <- .03 #MLPY (default value)
q_nap <- .01 #MLPY

p_jet <- 2.25 #/L (high price) p_dsl <- 0.96 #/L (high price)
p_nap <- 1 #$/L (high price)

financial info

life <- 25 #yr
t_cons <- 3
t_dep <- 10
t_loan <- 10 # loan term
r_dis <- 0.10 # deflated discount rate (default value)
r_eq <- 0.15 # rate of return
r_tax <- 0.21
debt <- .6

#######################################

BSP calculation

#######################################

Set inflation rate to 2%

inflation_rate <- 0.02

Calculate inflation factor for each year

inflation_factor <- (1 + inflation_rate)^(1:25)

CF0 <- capex0.08(1+r_dis)^2* inflation_factor[1]+capex0.6(1+r_dis)* inflation_factor[2]+capex0.32 inflation_factor[3]

irr <- r_eq
#irr <- r_eq-r_inf
CF0 <- capex0.08(1+irr)^2* inflation_factor[1]+capex0.6(1+irr)* inflation_factor[2]+capex0.32 inflation_factor[3]

Adjust expenses for inflation

exp_ut <- q_water * p_water* inflation_factor +
q_elec * p_elec* inflation_factor +
q_gas * p_gas* inflation_factor +
q_h2 * p_h2 * inflation_factor
exp <- exp_ut+q_fdp_fdinflation_factor+q_labp_labinflation_factor

sale_by <- (q_dslp_dsl+q_napp_nap)*inflation_factor

p_jet_range <- seq(0.1,100,by=0.01)

search within [0.1,100] to find a value yielding a NPV closest to zero

bsp_jet <- 1000 #default
bsp_npv <- 1000 #default
for (p_jet in p_jet_range){
sale <- sale_by+q_jetp_jetinflation_factor

cat("revenue share for meal:",q_meal*p_meal/sale,"\n")

ebitda <- sale - exp

Calculate annual depreciation

dep_per_year <- capex*.8/ t_dep
dep_schedule <- c(rep(dep_per_year, t_dep), rep(0, life - t_dep))
ebit <- ebitda - dep_schedule
amort <- amort.table(Loan=capex,n=t_loan,pmt=NA,r_dis)[["Schedule"]]

CF1 <- as.data.frame(amort) # cash flow for Y1-15
new_rows <- data.frame(Payment = rep(0, 15),
Interest Paid = rep(0, 15),
Principal Paid = rep(0, 15),
Balance = rep(0, 15))

names(new_rows) <- names(CF1)

CF <- rbind(CF1, new_rows)
CF$Year <- 1:25

CF$EBIT <- ebit
CF$EBT <- CF$EBIT-CF$Interest Paid
CF$Depreciation <- dep_schedule
CF$Flow <- CF$EBT*(1-r_tax)+CF$Depreciation-CF$Principal Paid
CF$Discount <- irr
CF$PV <- CF$Flow/(1+CF$Discount)^CF$Year
NPV <- sum(CF$PV)-CF0
if (abs(NPV)<bsp_npv){
bsp_jet <- p_jet
bsp_npv <- abs(NPV)
}
}

bsp_jet

'''
This gives me 6.13. The case where price is low:

'''

case 2

library(FinancialMath)
library(dplyr)
library(ggplot2)
library(plyr)
library(tidyverse)

plant info

q_fuel <- 29.88 #MLPY (million L/yr)
capex <- 214.11 #MM$ (million) capital exp (default value)
hrs <- 8406 #hr/yr

input info

q_fd <- 0.13 #M t/yr (million tonnes annually)
q_water <- 1.6 #M t/yr
q_elec <- 8.9 #M kWh/yr
q_gas <- 0.04 #M t/yr
q_h2 <- 0.007 #M t/yr
q_lab <- 55 #labor

p_fd <- 800 #/t (default value) p_water <- .57 #/t
p_elec <- 0.11 #/kWh p_gas <- .8 #/t
p_h2 <- 1210 #/t (default value) p_lab <- 0.043 #MM/labor

output info

q_jet <- 29.83 #MLPY (default value)
q_dsl <- .03 #MLPY (default value)
q_nap <- .01 #MLPY

p_jet <- 0.47 #/L (default value) p_dsl <- 0.82 #/L
p_nap <- 0.52 #$/L

financial info

life <- 25 #yr
t_cons <- 3
t_dep <- 10
t_loan <- 10 # loan term
r_dis <- 0.10 # deflated discount rate (default value)
r_eq <- 0.15 # rate of return
r_tax <- 0.21
debt <- .6

#######################################

BSP calculation

#######################################

Set inflation rate to 2%

inflation_rate <- 0.02

Calculate inflation factor for each year

inflation_factor <- (1 + inflation_rate)^(1:25)

irr <- r_eq
#irr <- r_eq-r_inf
CF0 <- capex0.08(1+irr)^2* inflation_factor[1]+capex0.6(1+irr)* inflation_factor[2]+capex0.32 inflation_factor[3]

Adjust expenses for inflation

exp_ut <- q_water * p_water* inflation_factor +
q_elec * p_elec* inflation_factor +
q_gas * p_gas* inflation_factor +
q_h2 * p_h2 * inflation_factor
exp <- exp_ut+q_fdp_fdinflation_factor+q_labp_labinflation_factor

sale_by <- (q_dslp_dsl+q_napp_nap)*inflation_factor

p_jet_range <- seq(0.1,100,by=0.01)

search within [0.1,100] to find a value yielding a NPV closest to zero

bsp_jet <- 1000 #default
bsp_npv <- 1000 #default
for (p_jet in p_jet_range){
sale <- sale_by+q_jetp_jetinflation_factor

cat("revenue share for meal:",q_meal*p_meal/sale,"\n")

ebitda <- sale - exp

Calculate annual depreciation

dep_per_year <- capex*.8/ t_dep
dep_schedule <- c(rep(dep_per_year, t_dep), rep(0, life - t_dep))
ebit <- ebitda - dep_schedule
amort <- amort.table(Loan=capex,n=t_loan,pmt=NA,r_dis)[["Schedule"]]

CF1 <- as.data.frame(amort) # cash flow for Y1-15
new_rows <- data.frame(Payment = rep(0, 15),
Interest Paid = rep(0, 15),
Principal Paid = rep(0, 15),
Balance = rep(0, 15))

names(new_rows) <- names(CF1)

CF <- rbind(CF1, new_rows)
CF$Year <- 1:25

CF$EBIT <- ebit
CF$EBT <- CF$EBIT-CF$Interest Paid
CF$Depreciation <- dep_schedule
CF$Flow <- CF$EBT*(1-r_tax)+CF$Depreciation-CF$Principal Paid
CF$Discount <- irr
CF$PV <- CF$Flow/(1+CF$Discount)^CF$Year
NPV <- sum(CF$PV)-CF0
if (abs(NPV)<bsp_npv){
bsp_jet <- p_jet
bsp_npv <- abs(NPV)
}
}

bsp_jet

'''
This one also gives same bsp_jet result: 6.13. Can anybody figure out what is wrong here? why is it giving me same result although I changed the prices (p_jet, p_dsl,p_nap)

p_dsl isn't defined.

with

for (p_jet in p_jet_range){
...
if (abs(NPV)<bsp_npv){
bsp_jet <- p_jet
bsp_npv <- abs(NPV)
}

You start a loop, assing new values to p_jet (from the p_jet_range) do some calculations, where none of the values are dependent on the given p_jet or p_dsl, and the result, the actual p_jet value that agrees to the limits is stored as result.
As it's a loop it should be the last value that fits into "if (abs(NPV)<bsp_npv)", not the best or closest one.