Apr 28, 2009 at 10:24am UTC
// 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;
}
Apr 28, 2009 at 7:43pm UTC
when i run the program it wont display the average? is that the correct way to use
cin << average; ?
Apr 28, 2009 at 7:46pm UTC
you are making a mistake here.
average = (numberOne + numberTwo + numberThree) / 3);
and
Last edited on Apr 28, 2009 at 8:01pm UTC
Apr 28, 2009 at 7:47pm UTC
Last edited on Apr 28, 2009 at 7:48pm UTC
Apr 28, 2009 at 8:09pm UTC
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
Apr 28, 2009 at 8:40pm UTC
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 )) ???
Apr 28, 2009 at 9:04pm UTC
you have extra ')' in expression average = (numberOne + numberTwo + numberThree) / 3);