A Question Based Off An Answer Off Myfirstprogram


Recommended Posts

jcl, you said "cstdlib' contains the declaration of system()"

but in my program

// This is a test program
#include <iostream>
#include <iomanip>

using namespae std;

int main ()
{
       init grade, total, gradeCounter;
       double average;

       system ("clear");

       cout << "Enter Grade or -1 to finish";
       cin >> grade

while ( grade != -1) {
       total += grade;
       ++gradeCounter;

}

if ( grade != -1) {

       average = static_cast< double> (total) / gradeCounter;

       if ( average >= 60)
               cout << "you pass!! with a grade point average of: " << average << endl;
       else
               cout << " You Failed!! with a Grade point average of: " << average << endl;
}

else
       cout << "You did not enter any Grades!!!!" << endl;

return 0;
}

you will see I did not add this.. why does it still work.. does gcc add the correct libs when I don't?

Link to post
Share on other sites

// This is a test program
#include <iostream>
#include <iomanip>

using namespace std;

int main ()
{
       int grade, total, gradeCounter;
       double average;

       total = 0;
       gradeCounter = 0;

       system ("clear");

       cout << "Enter Grade or -1 to finish ";
       cin >> grade;

while ( grade != -1) {
       total += grade;
       ++gradeCounter;

       cout << "Enter Grade or -1 to finish ";
       cin >> grade;
}

if ( grade != -1) {

       average = static_cast< double > ( total ) / gradeCounter;

       if ( average >= 60 )
               cout << "you pass!! with a grade point average of: " << average  << setprecision( 2 ) << fixed << endl;
       else
               cout << " You Failed!! with a Grade point average of: " << average << setprecision( 2 ) << fixed << endl;
}

else
       cout << "You did not enter any Grades!!!!" << endl;

return 0;
}

ok this is not working no matter what I enter I get "you did not enter any grades???"

Link to post
Share on other sites

so stupid.. my if should check gradeCounter not grade... man this language makes me feel stupid..

Link to post
Share on other sites
jcl, you said "cstdlib' contains the declaration of system()"

It looks like the iostream header indirectly pulls in cstdlib. It's not portable behavior as far as I know.

man this language makes me feel stupid..

Not an uncommon problem. Wait till you get into templates. Sometimes I can't believe people use C++ at all.

Edited by jcl
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...