Question[Help]My Learning Status

Posts 1–15 of 21 · Page 1 of 2
[Help]My Learning Status
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.
Quote Originally Posted by Kallisti View Post
[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, I already figured that one out, smart one. /
I am looking for a way to figure out how to MAKE that NOT happen. lolz.
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;
Quote Originally Posted by Gab View Post
What does that line do?

Code:
 cout << endl;
it skips a line. endl = \n
Quote Originally Posted by Gab View Post
What does that line do?

Code:
 cout << endl;
lolz. Are you for real??
You haven't learned that yet?

cout is the (see-out) You output text with it.
endl is (end line) You skip that line and start the text on the NEXT one.
Quote Originally Posted by Void View Post
I always use \n

|:
Quote Originally Posted by Kallisti View Post


Me too

easier is easier.
Yeah, \n and endl; have the SAME outcome, but IDK, I have been using endl; since I started, so I guess for me it's easier. :-|

But whenever I learn to write BIG complex programs, most likely i'll use \n to make it less typing. lolz.
Quote Originally Posted by DBag4Life69 View Post


lolz. Are you for real??
You haven't learned that yet?

cout is the (see-out) You output text with it.
endl is (end line) You skip that line and start the text on the NEXT one.
Yes I know what's a cout and an endl.... But please use \n... MORE PROFESSIONAL
Quote Originally Posted by Gab View Post
Yes I know what's a cout and an endl.... But please use \n... MORE PROFESSIONAL
I'm sorry, this post fails.

Who says it's more professional? You don't even know much C++
I always use \n

|:
Quote Originally Posted by Void View Post
I always use \n

|:
Me too

easier is easier.
Code:
if (yourpercentagevariablehere > 100)
    yourpercentagevariablehere = 100;
wow very hard.
Posts 1–15 of 21 · Page 1 of 2

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us