[php]cout << "Percentage outta the C++ Primer Plus: 5th Edition: " << pages / CppPrimer * 100 << "%" << endl; [/php]
1230/1225 = 1.004
1.004 * 100 = 100.4.
I pointed out why it's doing it, though i won't give any code.
Okay guys,
I have this code I have been messing around with a little bit that I wrote on my own, as a way to take what I am currently learning from the book I am reading, and put it into something more than just retyping source codes that're in the book. I want to try many different methods that'll produce practically the same outcome for this simple program.
The whole point here with this program is for me to enter the amount of pages I have read, and have it automatically calculate the percentages for me to update my sig with, of my C++ Learning Status.
What I am having a problem with here is I have it set up where it outputs the percentage I am on the CURRENT book I am reading, and the total percentage outta the 2(soon will be MORE) books I have on C++. The problem is that when I am done with the first book(1225 pages long) and I start on my other book, that means I will have read for example 1230 pages(5 pages of the next book and ALL 1225 of the first), it doesn't make the FIRST book stop at 100% it makes the percentage of the first book show as 100.41%. I need some advice on how to get this to stop at 100% but for it to STILL count up the total percentage.
Here's my code::
[php]
// Credits:
// D-Vid aka Illusionz -- DBag4Life on MPGH
// flashlight95 -- For the idea of using the if
// crash
#include <iostream>
int main()
{
using namespace std;
float CppPrimer = 1225;
float total = 2501;
int pages;
cout << "Enter the total amount of pages that you've read so far: \n\n";
cin >> pages;
cout << endl;
if (pages>total)
{
cout << "You input the incorrect value, it has to be less than 2501 pages." << endl;
system("PAUSE");
cout << endl;
}
else if (pages<total)
{
cout << "Percentage outta the C++ Primer Plus: 5th Edition: " << pages / CppPrimer * 100 << "%" << endl;
cout << "Percentage TOTAL outta all the books: " << pages / total * 100 << "%" << endl;
system("PAUSE");
cout << endl;
}
else
{
cout << "You're DONE learning from those books!" << endl;
system("PAUSE");
cout << endl;
}
return 0;
}
[/php]
I would like to hear some constructive criticism, but I don't want any flaming. I AM new at C++, and I am trying to learn different styles of coding.
[php]cout << "Percentage outta the C++ Primer Plus: 5th Edition: " << pages / CppPrimer * 100 << "%" << endl; [/php]
1230/1225 = 1.004
1.004 * 100 = 100.4.
I pointed out why it's doing it, though i won't give any code.
未来が見えなくて怖いから
未来が見えてしまって悲しいから
目を閉じて優しい思い出に浸ってしまう
Well, it's saying percentage from C++ primer, why would you want to show added percentage from both?
未来が見えなくて怖いから
未来が見えてしまって悲しいから
目を閉じて優しい思い出に浸ってしまう
I think I made it do what I wanna do, but it's not 100% fixed yet.
It keeps wanting to terminate itself when I put 1225 as the amount of pages... :-|
[php]
// Credits:
// D-Vid aka Illusionz -- DBag4Life on MPGH
// flashlight95 -- For the idea of using the if
// crash
#include <iostream>
int main()
{
using namespace std;
float CppPrimer = 1225;
float VCpp = 1276;
float total = 2501;
int pages;
cout << "Enter the total amount of pages that you've read so far: \n\n";
cin >> pages;
cout << endl;
if (pages>total)
{
cout << "You input the incorrect value, it has to be less than 2501 pages." << endl;
system("PAUSE");
cout << endl;
}
else if (pages<total)
{
if (pages>CppPrimer)
{
cout << "Percentage outta the C++ Primer Plus: 5th Edition: 100%" << endl;
cout << "Percentage TOTAL outta all the books: " << (pages/total)*100 << "%" << endl;
system("PAUSE");
cout << endl;
}
else if (pages<CppPrimer)
{
cout << "Percentage outta the C++ Primer Plus: 5th Edition: " << (pages / CppPrimer) * 100 << "%" << endl;
//cout << "Percentage outta the Visual C++ 2010: " << (pages / VCpp) * 100 << "%"<< endl;
cout << "Percentage TOTAL outta all the books: " << (pages / total) * 100 << "%" << endl;
system("PAUSE");
cout << endl;
}
}
else
{
cout << "You're DONE learning from those books!" << endl;
system("PAUSE");
cout << endl;
}
return 0;
}
[/php]
[php]if(pages==CppPrimer)
{
cout << "Done with CPP Primer\n";
cout << "0% with others\n";
//rest?
}[/php]
未来が見えなくて怖いから
未来が見えてしまって悲しいから
目を閉じて優しい思い出に浸ってしまう
What does that line do?
Code:cout << endl;
Melodia (09-26-2010)
wow very hard.Code:if (yourpercentagevariablehere > 100) yourpercentagevariablehere = 100;