Re: Woops, forgot the code.

  • From: "Jacob Kruger" <jacobk@xxxxxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Wed, 7 Jul 2010 10:21:29 +0200

All would do myself generally would be to change the following to something 
like this:
 answer = (score_1+score_2+score_3)/3;

Not too sure about this language specifically, but certain types of 
mathematical calculations might have priority levels, so that the score_3 would 
then be divided by 3 and then added to the two others, but if you make sure the 
initial additions are made first before doing the division, it might just be 
safer.

Stay well

Jacob Kruger
Blind Biker
Skype: BlindZA
'...fate had broken his body, but not his spirit...'

  ----- Original Message ----- 
  From: Jes 
  To: programmingblind@xxxxxxxxxxxxx 
  Sent: Wednesday, July 07, 2010 10:08 AM
  Subject: Woops, forgot the code.


  Here's the code.
  //Ch5 Exercise 4, page 287 //Calculates and displays the average of three 
test scores
  //created/revised by Jes Smith on July 5 2010


  #include <iostream>



  using namespace std;
   //begin program
  int main()
  {
  //declare variables
  double score_1=0;
  double score_2=0;
  double score_3 (0);
  int answer;
  cout<< "This program takes three test score numbers you enter, and figures 
out the average for you. ";
  cout<< "Please enter your first test score, then press enter. Decimal values 
accepted: " ;
  cin >> score_1 ;
  cout<< "Please enter your second  test score. Remember to press enter when 
done: ";
  cin >>score_2  ;
                  cout<< "Finally, enter your third   test score.";
  cin >>score_3  ;
   answer = score_1+score_2+score_3/3;
   cout<<"The average is " <<answer;


  return (0);
  } //end of main function.




  __________ Information from ESET NOD32 Antivirus, version of virus signature 
database 5257 (20100707) __________

  The message was checked by ESET NOD32 Antivirus.

  http://www.eset.com



__________ Information from ESET NOD32 Antivirus, version of virus signature 
database 5257 (20100707) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

Other related posts: