944,188 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 4165
  • C++ RSS
Nov 14th, 2004
0

percentage

Expand Post »
I've written programs for averaging lists of exam grades but throwing in the percent is throwing me for a loop. I don't know how to handle this information. Any help will be greatly appreciated.


//Write a program that asks the user to enter a student's midterm
//and final exam scores. The program should display the midterm and
//final exam scores and the student's final grade. Compute the final
//grade by taking the sum of 40% of the midterm exam score and 60% of
//the final exam score.

#include <iostream.h>
#include<iomanip.h>

//using namespace std;

int main()
{
int. midterm,midterm;
final;final;
double 40% mid;
60% final;

cout<< set precision()
<<setiosflags(.40);
<<setiosflags(.60);

//obtain input data
cout<<"\nEnter midterm";
cin>>midterm exam;
cout<<"\nEnter final";
cin>>;final exam;

//Do the calculations
final grade = double (midterm + final);
cout<<"\n;????

return 0;
}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
old lady is offline Offline
3 posts
since Nov 2004
Nov 14th, 2004
0

Re: percentage

Is it compiling? I am not 100% confident with c++ but I don't think what your doing is possible. Try something like this...

final_grade = (.4*midterm)+(.6*final);
Reputation Points: 11
Solved Threads: 2
Junior Poster in Training
jasweb2002 is offline Offline
56 posts
since Sep 2004
Nov 16th, 2004
0

Re: percentage

Thank you. It is surprising how one little thing like a percentage can totally destroy my brain. I haven't compiled this yet but I think it might work.

#include <iostream.h>
using namespace std;
int main()
{
float midterm, final, average;
cout<<"Enter a midterm grade:";
cin>>midterm;
cout<<"Enter a final grade:";
cin>>final;
average=(.4f*midterm)+(.6f*final);
cout<<"the average is:"<<average<<'\n';
return 0;
}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
old lady is offline Offline
3 posts
since Nov 2004
Nov 16th, 2004
0

Re: percentage

average=(.4f*midterm)+(.6f*final);

What are the f's for?
Reputation Points: 11
Solved Threads: 2
Junior Poster in Training
jasweb2002 is offline Offline
56 posts
since Sep 2004
Nov 16th, 2004
0

Re: percentage

In Java you would write .4f to force the floating point literal into a float instead of a double datatype.
Don't think C++ works like that.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC