0

Some help please for a rookie

I wrote a program to calculate tip amount on a bill where you input the bill amount and input the percentage you want to tip. Low and behold i got it to work,however, say I input bill amout of $97 and tip percentage of 20% the outcome is $19.4. How do i make it return $19.40? Here is my code: #include <iostream> using namespace std; /* I am at best a rookie at this. if someone can help me to figure out how to make a second decimal place after the decimal even if its 0 i would appreciate it. For example: Tip:$19.40 instead of Tip:$19.4 thank you.*/ int main() { float a; float b; float c; cin>>a;//enter bill amount// cin>>b;//enter tip percentage// c=a*(b/100); cout<<"Your bill:

quot;<<a<<endl; cout<<"tip percentage:"<<b<<"%"<<endl; cout<<"tip amount:
quot;<<c<<endl; return 0; }

11th Sep 2016, 5:27 AM
David
2 Respuestas
0
hey ! Why dont u try this - cout<<"tip amount:"<<c<<"0"<<endl ; I m nt sure bt maybe it works . Try it out !
11th Sep 2016, 7:26 AM
Programmer
0
Thank you for the reply! That would work for some but not all instances. For example: If the output would be 19.4 that would change it to 19.40 like I want; If the output would be 33.33 that would change it to 33.330 which i wouldnt want. Ive done a little research and I am going to try to add in a couple lines to see if it works: Cout<<std::fixed; Cout<<std::setprecision(2);
11th Sep 2016, 11:53 AM
David