Answer to Question #195826 in C++ for Shob

Question #195826

Create an int array called gamesWon[] of capacity 100, that stores the number of games won in different chess tournaments in the last two years. and fill n elements of this array by prompting a player to enter data and ask to end the data by entering Q. You use a while loop to read the user entered data and assign to the elements of the array. So it is important to use a new variable and initialize it to 0 and use as the index of the array as well. The value of this variable when the sentinel value is read is the actual size of the array. Now you have a partially filled array. Print the array you created using the variable you used as index variable as the size of the array.

1.Find and print the smallest number of games won in a tournament by the player.


1
Expert's answer
2021-05-21T05:15:05-0400
#include <iostream>
#include <string>
 
using namespace std;
 
int main()
{
	string temp;
	int gamesWon[100];
	int size = 0;
	cout << "Enter number of games won (Q to exit)." << endl;
	while (true)
	{
		cout << "#" << size + 1 << ": ";
		cin >> temp;
		if (temp == "Q") break;
		gamesWon[size] = stoi(temp);
		size++;
	}
	cout << "Entered array: ";
	int min = gamesWon[0];
	for (int i = 0; i < size; i++)
	{
		if (min > gamesWon[i]) min = gamesWon[i];
		cout << gamesWon[i] << " ";
	}
	cout << endl;
	cout << "The smallest number of games won in a tournament by the player is: " << min << endl;
	system("pause");
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog