0

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);
}

3
Contributors
4
Replies
5
Views
11 Years
Discussion Span
Last Post by Bench
0

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......

0

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

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.