Run Time Error

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
Is it actually an error? I think the code should still run, you just don't have the C++ debugging symbols.
But if you want to prevent this, see the answer linked here: https://stackoverflow.com/a/30534976/8690169
closed account (E0p9LyTq)
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
Can I just tell it to divide by 3 where numberOfScores is?

// Calculate average
average = (score1 + score2 + score3)/numberOfScores;

Yes you can do either:

1
2
// Calculate average
average = (score1 + score2 + score3)/3;


or when defining numberOfScores, set it to 3 instead of 0

 
int numberOfScores = 3;
Thanks everyone. Much appreciated.
Topic archived. No new replies allowed.