• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Need help writing a pseudocode for an algorithm. Solved: thanks m0ti, anahang, and others that contirbuted.

imported_vr6

Platinum Member
ok heres the Problem

Mrs Match went to a store, Spent half of her money and then $10more. She went to a second store, spent half the money she had left and 10more. Shen then had no money left. How much money did Mrs Match have when she first started out?

Key points.
1. Mrs Match should always have no money at the end.
2. The user should specify the number of stores.
3. The users should specify the "amount more" that mrs. match spends at each store, but it will be the same amonut at each store.

I don't even know where to begin except that i need these inputs:

1. # of stores she will visit.
2. Amount more spent at each store.

Any ideas?

I don't even know what the equation looks like... HELP!
 
well heres the eqn:
((x/2+10)/2)+10)=0

is the point of this program to just determine how much she has? like the eqn above?


Imhotep MP



 
its been a hella long time since i did any coding or algorithmic math for that matter...but from what you explained thus far, just to clarify if i'm inperpretating this correctly, it sounds like your trying to do the following:

Write a program that would take a user's input which would represent the amount of stores Mrs Match visited. Then from that input, have the program determine how much she had to originally start off with in order to have an end balance of 0 after visiting that amount of stores.

if this is the case, then starting from the end and going backwards, she would have to have 20 dollars going into the last store visited. and from there you would get the following going into each store:

20 = last store
60 = 2nd to last store
140 = 3rd to last store
300 = 4th to last store
etc.

now there's no patter looking at these numbers, but if you look at the difference between each number:
40 = difference between last and 2nd to last store
80 = difference between 2nd and 3rd to last store
160 = difference between 3rd and 4th to last store

so with each one, it doubles, 40*2=80, 80*2=160, etc
i think this may play a part in your pseudocode....i may be wrong tho, its been a while...i'll work on it tho, i'm working nightshift, so i got time to kill..thanx for the challenge...😀
 
recursion anyone?

int f(int money left){

if (money left <= 0)
return (0)
else
return (f(money left / 2 -10 )

}

user intputs stores and and amt_over_half



so going forward U CAN USE THIS AS PSEUDOCODE 🙂

stores = user input1;
int amt_over_half = user input2;
cash initialized to zero (value parameter)



int f ( int stores, int cash)

{
if (stores = 0)
return (cash)
else
return ( f (stores -1, cash * 2 +amt_over_half)
}








 
ok, this is what i came up with...its sloppy tho and i'm sure the syntax is whack, but its pseudocode right?..hehe...not even sure if its right, but it seems to be every time i step thru it:

int total = 20 //starting amount of money

proc calculate //start of calc procedure

total = (total + 10) * 2
stores = stores - 1
if stores == 0
exit
else
calculate

end calculate //end of calc procedure

proc UserInput //starting of user input
if stores = 1
{
total = 20
exit
}
else
stores = stores - 1
calculate
end UserInput //end of user input

proc main
int stores
user inputs value for stores
UserInput //call procedure UserInput
print total
end main
 
ok i am looking and studying everyone of these... i am pretty bad at this stuff since this is my first CMSC class. im only in CMSC 104, so i am clueless myself.. and the professor sucks he done't explain well at all! and when u ask a question he makes you feel stupid and no answer your question!

Let me do some studying and i'll be back!

Thanks for the help guys!
 
hey anahang, i looked at your post and I Don't think i am suppose to be using any number of stores or amount of money spent extra. The program is suppose to let you enter any number or stores and any number or amount extra spent. any ideas?

let me see if i can change some stuff from your post and see what i come up with.. thanks for the help, i appreciate it!
 
i am looking and i realize that you guys are giving me pseudocode for C++. I need to have generic pseudocode that is not gear toward any programming language.

For example this is the first problem from the HW that i think i got.

Example.

Mrs shoe kep 2 meatball for herself, then divided the other equally among her 14 children. If each child got 5 meatballs, how many did mrs shor have to begin with?

Generic Pseudocode:

Prompt User to enter # of meatballs to keep for Mrs Shoe.
Input number of meatballs for Mrs shoe
Do while (Meatball <0)
Prompt user to enter # of meatballs with value > or = 0
End Do

Prompt user to enter # of children
Input number of children.
Do While ( Children < 0)
Prompt user to enter # of children with value > 0
End Do

Prompt user to enter # of meatball per child.
Input # of meatballs per child
Do while (meatball per child is < 0 )
Promt user to enter # of meatball with valus > 0
End Do

Compute total # of meatballs
Total # of meatballs <- (# of meatballs to keep for mrs shoe) + (# of Children)*(# of meatballs per child)

Display # to keep for Mrs. Shoe and # of children and # of meatball per child.
Display total amount of meatballs.





I think i did this problem right and thats the format its suppose to be in. Sorry i didn't explain this earlier.

Any ideas?
 


<< well heres the eqn:
((x/2+10)/2)+10)=0

is the point of this program to just determine how much she has? like the eqn above?
>>



Yes the equation is suppose to tell how much money She have if you only know the number of stores she went to and the amount extra spent.

I am trying to figure out a Generic equtaion for this problem. Meaning using two variables to stand in for The number of stores visited and the Amount extra she spents at each store.
 
Define $ (amount to have at beginning).
Define M (amount extra to spend in each store).
Define N (# of stores in which to spend).

Define T=0.

(for i=0 to N-1)
{T=T+[(.5)^i]*M}.

$=T/[(.5)^N]

That's it. Let's check it.

Say you have 3 stores and you want to spend $10 extra per store.

So the amount of money that she had to begin is

[(.5^2)*10+(.5^1)*10+(.5^0)*10]/(.5^3)=140.

keep in mind that .5^0=1.

Then 140 ======> 60 ======>20======>0.
...............-(70+10)........-(30+10)......-(10+10)

Try it with 2 stores.

[(.5^1)*10+(.5^0)*10]/(.5^2)=60.

We see that this was in the previous one and it worked.

Let's try with subtracting 5, with 3 stores.

[(.5^2)*5+(.5^1)*5+(.5^0)*5]/(.5^3)=70.

So 70 ======>30======>10=====>0.
..........-(35+5).......-(15+5)........-(5+5)

Well this seems to work. I forgot how to do C++ so I can't check it for sure, but it seems to work for now.

[edit]: trying to get it to look nice... gimme a minute.... okay, the periods have to do to make the stuff line up.
 


<< $=[(SIGMA(i=0 to N-1) ((1/2)^i)*M]*1/((1/2)^N) >>



hymm.. I am new to programming, so let me take a stab at what this means.

Starting money <- [(.5^(Number of stores visited-1))*Amount Extra Spent]/(.5^number of stores visited)

 
but then let say if i am doing 4 stores then would that (Number of stores visited-1) only give me only store number 3? how would i make sure it keeps going until the number of stores visited is equal to Zero?
 
hey Kwan1...sorry i misunderstood what your prog was supposed to do, anyway, to clarify and confirm again, i've gone about it this way:

user inputs the amount of stores and the amount of extra money to be spent at each store (same amount per store), then output what mrs. match originally started off with...i've added more comments to make it more clear what each line is doing in an effort to help you translate it to the pseudocode standard that you need...i hope this helps and hope i got it right this time...hehe..its been a while...

proc calculate //start of calc procedure

total = (total + extra) * 2 //the new value of total will be (its current value plus the extra money) multiplied by 2
stores = stores - 1 //keeping count of how many stores is equivalent to how many times to do the arithmetic
if stores == 0 //if the value of stores is now 0, that means that all calculations are done
exit //when all calculations are done, exit this cycle
else //if all calculations are not done, then repeat the cycle
calculate

end calculate //end of calc procedure

proc main
int total = 0 //starting amount of money
int stores //amount of stores to be input by user
int extra //amount of extra cash spent at each store

user inputs value for stores
user inputs value of extra money
calculate //call procedure calculate
print total //print total amount of money mrs. match originally started off with

end main
 
I finnaly got this thanks anahang for all your input. I appreaciate all your help. Another member member by the name of m0ti broke it down into small chuncks for me and came up with the final equation of

2A(2^n-1) if you repeat that equation until n-1 equals zero it works.

I am pretty sure this is the same thing you guys are telling me here too, but i am too dumb to understand the programming short hands. If you are interested you can view my other thread here.

Other thread

Thanks for the input guys.
 
Back
Top