944,058 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1538
  • C++ RSS
Feb 27th, 2006
0

needing help figuring out

Expand Post »
hi, i can figure out why this program keeps counting up the cash variable more than once when i run it, like it'll be
10
10
10
10
10
11
11
11
11
11

and the percentage numbers have the letter "e" at the end of each percentage...

just seeing if i could get a hand cause i am stumped


// Produce a two-column table with column headings showing P% if the amounts$ 1$,2$,3$,...,20$. P is to be input,
____________________________________________________________________________________________________________________________________________________________


#include <iostream.h>
#include <conio.h>




int main()
{
double percentage,num2;


cout<<"Please insert percentage: ";
cin>>percentage;
num2=percentage*.01;

for(double cash=1;cash<=20;cash=cash+1)
{
num2=num2*cash;
cout<<num2<<endl;
cout.width(10);cout<<cash<<endl;
cout<<num2<<endl;
cout.width(10);cout<<cash<<endl;
cout<<num2<<endl;
cout.width(10);cout<<cash<<endl;
cout<<num2<<endl;
cout.width(10);cout<<cash<<endl;
cout<<num2<<endl;
cout.width(10);cout<<cash<<endl;
cout<<num2<<endl;
cout.width(10);cout<<cash<<endl;
cout<<num2<<endl;
cout.width(10);cout<<cash<<endl;
cout<<num2<<endl;
cout.width(10);cout<<cash<<endl;
cout<<num2<<endl;
cout.width(10);cout<<cash<<endl;
cout<<num2<<endl;
cout.width(10);cout<<cash<<endl;
cout<<num2<<endl;
cout.width(10);cout<<cash<<endl;
cout<<num2<<endl;
cout.width(10);cout<<cash<<endl;
cout<<num2<<endl;
cout.width(10);cout<<cash<<endl;
cout<<num2<<endl;
cout.width(10);cout<<cash<<endl;
cout<<num2<<endl;
cout.width(10);cout<<cash<<endl;
cout<<num2<<endl;
cout.width(10);cout<<cash<<endl;
cout<<num2<<endl;
cout.width(10);cout<<cash<<endl;
cout<<num2<<endl;
cout.width(10);cout<<cash<<endl;
cout<<num2<<endl;
cout.width(10);cout<<cash<<endl;
cout<<num2<<endl;

}
cout<<endl;
return(0);
}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
caseg is offline Offline
13 posts
since Jan 2006
Feb 27th, 2006
3

Re: needing help figuring out

Huh? What are you trying to do here?
Team Colleague
Reputation Points: 1135
Solved Threads: 172
Super Senior Demiposter
Rashakil Fol is offline Offline
2,479 posts
since Jun 2005
Feb 27th, 2006
0

Re: needing help figuring out

well i am supposed to multiple my cin>> variable by .01, and you have to figure out the percentage of the dollars 1-20 for the variable X .01......
Reputation Points: 10
Solved Threads: 0
Newbie Poster
caseg is offline Offline
13 posts
since Jan 2006
Feb 27th, 2006
0

Re: needing help figuring out

pretty much on the left i must have the input*.01*cash(the one to the righ of it)
and on the right ill have the cash number
Reputation Points: 10
Solved Threads: 0
Newbie Poster
caseg is offline Offline
13 posts
since Jan 2006
Feb 27th, 2006
0

Re: needing help figuring out

The whole idea of 'for' loops is that you type the code once, and the loop will repeat it. The reason you are getting the same output multiple times is that you have the same 2 lines occurring 20 times.
Reputation Points: 307
Solved Threads: 62
Posting Pro
Bench is offline Offline
565 posts
since Feb 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: C++ homework Problem
Next Thread in C++ Forum Timeline: How to use interface of a dll which is developed in C#>NET in my VC++.NET appli





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC