Jun 7, 2018 at 7:55pm UTC
This is my 1st time working with C++ and Visual Studio.
I know the drivers are not found as well as "It could not find or open the PDB file. How do I fix the error?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#include <iostream>
using namespace std;
int main()
{
double score1, score2, score3, average;
int numberOfScores = 0;
cout << "Program to computes average of trhee scores" <<endl<<endl;
// Prompt user to enter input
cout << "Enter score1: " ;
cin >> score1;
cout << "Enter score2: " ;
cin >> score2;
cout << "Enter score3: " ;
cin >> score3;
// Calculate average
average = (score1 + score2 + score3)/numberOfScores;
// Output result
cout <<"The average is: " << average<<endl;
cin.get(); cin.get();
return 0;
}
Last edited on Jun 7, 2018 at 8:27pm UTC
Jun 7, 2018 at 8:08pm UTC
PLEASE learn to use code tags, they makes reading your source code MUCH easier and helps to point out problems with your code.
HINT: you can edit your post and add the code tags.
http://www.cplusplus.com/articles/jEywvCM9/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#include <iostream>
int main()
{
double score1, score2, score3, average;
int numberOfScores = 0;
std::cout << "Program to computes average of trhee scores:\n\n" ;
// Prompt user to enter input
std::cout << "Enter score1: " ;
std::cin >> score1;
std::cout << "Enter score2: " ;
std::cin >> score2;
std::cout << "Enter score3: " ;
std::cin >> score3;
// Calculate average
average = (score1 + score2 + score3) / numberOfScores;
// Output result
std::cout << "The average is: " << average << '\n' ;
}
Program to computes average of trhee scores:
Enter score1: 2
Enter score2: 3
Enter score3: 4
The average is: inf
When you calculate your average you are dividing by zero, numberOfScores = 0 and isn't changed.
Using VS 2017 community the source code for me compiles (and runs) without any errors.
The output is still wrong from dividing by zero.
Last edited on Jun 7, 2018 at 8:10pm UTC
Jun 7, 2018 at 8:16pm UTC
Can I just tell it to divide by 3 where numberOfScores is?
// Calculate average
average = (score1 + score2 + score3)/numberOfScores;
Jun 7, 2018 at 8:41pm UTC
Thanks everyone. Much appreciated.