Hey. I'm having some trouble writing a program. I just begun C++ and don't know the language all that well. I've gotten a small start to the program and could really use some pointers.
Here are the program descriptions:
Read list of strings and store strings in array of strings.
Max. of 10 strings
Let n be the actual number of strings read
Use length function to find the length of each string. Store lengths in int array.
Find longest string and average length of all strings.
The output should be displayed in columns. Print the columns with a fixed field width=longest-word-length + 3. Avg. should be printed as a float with two decimal places.
Ok. So, that is what we know.
I know that I will need to define an array. I will have to use a for-loop. I will have to use the .length() statement. I need iomanipulators, setw() and setprecision(). I have all of this figured out and have begun writing the program some, and it's kind of broken -- so far this is what I have......
#include <iostream>
#include <iomanip> // For setw() and setprecision()
#include <string>
using namespace std;
const int MAX_SIZE = 10;
int main ()
{
//Variable Declarations
int n; // Number of strings to be read
int i;
string a[MAX_SIZE];
float avgLength; // Average length of the strings
string longestWord; // Longest word given
int lengthofLongest; // Length of the longest word given
for (i=0; i < 10; i++)
{
cout << "Enter the number of strings:" <<
cin >> n >> endl;
cout << "Enter a string:" <<
}
From here I don't really know where to go. I'm not sure I made correct variable declarations. I don't know where I should put in the array and make it come into play. I know it goes into the for-loop. Then, I'm not sure where I should use the .length() statement.
Could someone please help me out just a little bit on the next step of solving this program and getting it to run correctly. Thank you!