Jump to content

Recommended Posts

Ok.

 

So I'm writing a program for a bodyshop. Customers are asked 11 questions all with yes or no answers.  Yes is good, no is bad. From that they can take the overall % for the month and see what the approve rating is.

 

I had a format I thought was going to work but as I got into it, it doesn't seem like it is going to work.

 

Example:

 

$a = 10; // How many questions did he answer yes to

$b = 357; // How many customers they had this month

 

Format:

 

$c = ($a * 100) / $b;

 

echo"$c";

OUTPUT = 2.8%

 

But that is just one customer. If I tallied up all the yes answers eventually they would be more than what I'm dividing them by and defeat the function.

 

What should I do? Any ideas?

 

We also want a way to track the overall approval rating for the past 12 months.

Link to comment
https://forums.phpfreaks.com/topic/71952-need-help-with-some-php-math/
Share on other sites

Well I dont' know how that would work.

 

Because lets say I have five customers.

 

1) 35.7%

2) 93.6%

3) 99.2%

4) 100%

5) 78.4%

 

I want to talley all of them up for an average for the month. What can I do?

And how can I do it with a couple of hundred customers a month?

 

when are you going to work up the percentage? Each time a customer enters their info? Or at the end of the month?

 

You could use the $d = ($a/$c) * 100; formula above to get each person's answers.

 

If you placed the answers into an array as customers submitted their answers you could figure out the percentages in "real time" $month = (array_sum($d) / count($d)) * 100;

You will need to do a seperate calculation. Dont take their percentages. Instead add up the total number of customers you have asked questions to, lets say 750. Then take the total number of customers that had been approved, lets say 556.

 

Then do

 

(556 / 750) *100

 

 

Surely if you ask 100 customers 10 questions each, then the total number of questions asked is 1000. If overall 300 questions were answered with a yes, then you need to work out the percentage that 300 is of 1000:

 

<?php
$customers = 100;
$questions = 10;
$total_questions = $customers * $questions;
$positive_answers = 300;
$percentage = $positive_answers/$total_questions *100;
?>

Yeah that looks fine although make sure you put brackets around

<?php
$customers = 100;
$questions = 10;
$total_questions = $customers * $questions;
$positive_answers = 300;
$percentage = ($positive_answers/$total_questions) *100;
?>

 

Not sure if that will work to be honest. but you need to ensure $positive_answers/$total_questions is calculated first.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.