954,492 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

tutor is needed here plz.

Hello.. can someone teach me how to do this program.

This is the question.

1. An organization has aprox. $1000 available to be allocated in small amount to approved charities. Write a program that will read several amounts and ((report as soon as over $1000 has been allocated. << NOW this is the part that i didn't know how to do!))

2. Display the number of donations required to exceed $1000.
For example in the output ATTACHED this message should be displayed: "4 donations were made" << this also didn't know how to do it.

Please note that i didn't take arrays yet.. so i'm not suppose to use them.. i only took loops, if-else, switch, and functions.

This is what i know.. so far:

# include <iostream>
using namespace std;

int main ()
{
	int x,i=0;

	do
	{
	
		cout<<"Please enter an amount: ";
		cin>>x;
	
	i++;
	
	}while(x<=1000);

return 0;
}
Attachments piC!!DANI.jpg 14.42KB
fadia
Junior Poster in Training
89 posts since Apr 2009
Reputation Points: 7
Solved Threads: 0
 

what your code currently does is, it stops when any single amount is greater than 1000. you need to come up with a way to "keep track" of what has already been allocated.

sillyboy
Practically a Master Poster
686 posts since Mar 2007
Reputation Points: 85
Solved Threads: 64
 

i'm already aware of that and have been thinking of a way to do so.. but didn't know how!!

fadia
Junior Poster in Training
89 posts since Apr 2009
Reputation Points: 7
Solved Threads: 0
 

do you know the concept of a counter variable? perhaps it will help you.

using a single variable x, you can only store the current value. you need to be able to store a cummulative values (which will be stored in your counter).

hope that helps

sillyboy
Practically a Master Poster
686 posts since Mar 2007
Reputation Points: 85
Solved Threads: 64
 

i have a counter in the program..
it's i++
but i'm not sure if i used it the right way.

fadia
Junior Poster in Training
89 posts since Apr 2009
Reputation Points: 7
Solved Threads: 0
 

no, it's definitely not the right way. for a start, the counter should form your loop's condition statement (hint 1). furthermore, even if you were using your counter as part of the condition it would only check the number of allocations you have done, not the actual value allocated (hint 2).

have a think for a while, don't just reply in hope of getting code.

sillyboy
Practically a Master Poster
686 posts since Mar 2007
Reputation Points: 85
Solved Threads: 64
 

ur not being helpful here at all... thnx for ur hint and all
but i didn't understand a singal thing from u

thnx though.

fadia
Junior Poster in Training
89 posts since Apr 2009
Reputation Points: 7
Solved Threads: 0
 

I get the impression you aren't really trying here, produce some updated code with what you are trying...

maybe then I can give more assisstance.

sillyboy
Practically a Master Poster
686 posts since Mar 2007
Reputation Points: 85
Solved Threads: 64
 

hey fadia, i think this wil work 4 ur need. #include <iostream>

using namespace std;

int main ()
{
int x=0,Donate=0,i=0,l=1;
while(l==1)
{
if(Donate<1000)
{
cout<<"Please enter amount 4 DoantionNo: "<<i+1<<" ";
cin>>x;
Donate=Donate+x;
i++;
}
else
{
l=0;
cout<<"$"<<(Donate-1000)<<" over $1000 has been allocated in "<<i+1<<" number of donations";
}
}
cin>>x;
return 0;
}

auhuman
Newbie Poster
14 posts since Feb 2009
Reputation Points: 4
Solved Threads: 0
 

auhuman, Though you have made 4 posts, You have been here for about 4 month's i believe, So It is of the impression that you must be knowing about the workings of this forum.
Basic Rule On Homework Help
Though your motive was to help Fadia out, It should have been done by telling him what he had to accomplish and how can he do so , But, not by giving away code.

Secondly, In the code you have given, I think that the variable in the while loop l can be completely avoided, Or Should have been replaced by a type bool

Sky Diploma
Practically a Posting Shark
865 posts since Mar 2008
Reputation Points: 673
Solved Threads: 131
 

auhuman, Though you have made 4 posts, You have been here for about 4 month's i believe, So It is of the impression that you must be knowing about the workings of this forum. Basic Rule On Homework Help Though your motive was to help Fadia out, It should have been done by telling him what he had to accomplish and how can he do so , But, not by giving away code.

Secondly, In the code you have given, I think that the variable in the while loop l can be completely avoided, Or Should have been replaced by a type bool


ya ur right i shouldn't have given him the code.What shall i do now?

auhuman
Newbie Poster
14 posts since Feb 2009
Reputation Points: 4
Solved Threads: 0
 

Sky diploma!
Just so u know.. this is not a homework.. this was given to me in my quiz about one month ago.. and i didn't know how to solve it.
And now i'm having the final and studying for it. I'm trying to solve all exams i took before and didn't know how to do them on my own.
So this is not a homewrok.. and trust me I have other programs to study , i don't really have the whole day to try solving this, i already tried and didn't know or else i wouldn't post this here. Not to mention my panic before this exam! Actually Auhuman was the one who helped more than any of u!
Thanks Auhuman!!
I'll try to study his code now understand it.

fadia
Junior Poster in Training
89 posts since Apr 2009
Reputation Points: 7
Solved Threads: 0
 

what is the l for?

and i didn't understand this>> while (l==1)

fadia
Junior Poster in Training
89 posts since Apr 2009
Reputation Points: 7
Solved Threads: 0
 

what is the l for?

and i didn't understand this>> while (l==1)


It looks like another way to write a !done loop. These two are conceptually the same:

int l = 1;

while (l == 1)
{
    if (/*not more to do*/) l = 0;
    else
    {
        //do stuff
    }
}
bool done = false;

while (!done)
{
    if (/*not more to do*/) done = true;
    else
    {
        //do stuff
    }
}
Tom Gunn
Master Poster
733 posts since Jun 2009
Reputation Points: 1,446
Solved Threads: 135
 

>ya ur right i shouldn't have given him the code.What shall i do now?
Just read the forum rules and make sure that it doesn't happen again :)

tux4life
Nearly a Posting Maven
2,350 posts since Feb 2009
Reputation Points: 2,134
Solved Threads: 243
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You