RE: Woops, forgot the code.

Hi,

That's better. You got it right this time - congradulations.

One more note though, As Jacob said, it'd be helpful (for both you and your
computer) if you enclose the addition in parentheses (called operator
precedence). This will make sure that the addition happens first followed by
division, like:

answer = (score_1+score_2+score_3)/3;

Also, bare in mind that if you get the answer, the decimal prt i.e. the one
after the period would be gone. To avoid it, declare the answer variable as
a double.

Cheers,

Joseph P.S. Good job this time.

 

 

From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Jes
Sent: Wednesday, July 07, 2010 1:09 AM
To: programmingblind@xxxxxxxxxxxxx
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.

 

No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 8.5.439 / Virus Database: 271.1.1/2984 - Release Date: 07/06/10
18:36:00

Other related posts: