finding average?

// stand alone project
// finding an average from three numbers

#include <iostream>
#include <string>

using std::cout;
using std::cin;
using std::endl;
using std::string;

int main()
{

// displaying purpose

cout << "Average Calculator\n" ;


// collecting user input

int numberOne;
int numberTwo;
int numberThree;
int average;
int i;

cout << "Enter Number" ;
cin >> numberOne;

cout << "Enter_Number:" ;
cin >> numberTwo;

cout << "Enter_Number:" ;
cin >> numberThree;

// the math


average = (numberOne + numberTwo + numberThree) / 3);

cin >> average;
std::cin >> i;
return 0;

}
Yes?
when i run the program it wont display the average? is that the correct way to use
cin << average; ?
you are making a mistake here.

average = (numberOne + numberTwo + numberThree) / 3);

and
 
 cout<<average;



Last edited on
you need cout<<average; for output a value of varriable

read:
http://www.cplusplus.com/reference/iostream/cin/
http://www.cplusplus.com/reference/iostream/cout/
Last edited on
Also notice that you average would be an int so it will have its value truncated, to have a more precise value you should use a double variable and a double division
thanks for all the help, yeah i named float average and couldn't figure out why i wasnt getting acurate numbers back, now i know.

-masiht, i found your mistake here

cout << "average"; no quotations...but im having trouble figuring out why (N1 + N2 + N3) / 3;
was it the last )) ???
you have extra ')' in expression average = (numberOne + numberTwo + numberThree) / 3);
1
2
3
4
-masiht, i found your mistake here

cout << "average"; no quotations...but im having trouble figuring out why (N1 + N2 + N3) / 3;
was it the last )) ???


average is type integer and it doesn't need any quotations.

you could do it like this
 
cout<<"average = "<<average;
Topic archived. No new replies allowed.