Question

Write a program that asks the user to give you a number, then use that number...

Write a program that asks the user to give you a number, then use that number to read a number of strings equal to that number, and finally compute the total length

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/**
The c++ program that prompts user to enter number of string to enter.
Then prompt for strings. Then print total length of the strings entered
by user.
*/

//include header files
#include <iostream>
#include <string>
using namespace std;

int main()
{  

   //declare variables
   int size;
    int length=0;
   //create an pointer of type string
   string *words;

   cout<<"Give me some words."<<endl;
   cout<<"I will count the total number of characters they have. "<<endl;
   cout<<"How many words : ";
   //prompt for size
   cin>>size;

   //create array of pointers to read strints
   words=new string[size];
    for(int i = 0; i < size; i++)
   {

       cout<<"Enter a string : ";
       //prompt for words
        cin>>words[i];

       //The method length() retunrs length of the string
       //add lenght of the words to lenght
       length+=words[i].length();
    }

   //print total lenght of the strings
   cout<<"Your strings have total length "<<length<<endl;

   system("pause");
    return 0;

}

-----------------------------------------------------------

Sample output screen shot:

Give me some words I will count the total number of characters they have How many words2 Enter a string hello Enter a string

Add a comment
Know the answer?
Add Answer to:
Write a program that asks the user to give you a number, then use that number...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 2) Write a program in C/C++ that asks the user to enter a number then the...

    2) Write a program in C/C++ that asks the user to enter a number then the user's input value is passed to a function which increments the number by 10 and returns the result of the incrementation. Write the program to accomplish the increment using three (3) different techniques. To test each technique separately, the user should enter a different number for each of the three (3) techniques. Make sure that you compile and execute your program. Finally, provide screenshots...

  • Write a program that asks the user to enter a number ofseconds.• There are...

    Starting Out with C++ (9th Edition)  Chapter 4, Problem 7PCWrite a program that asks the user to enter a number of seconds.• There are 86400 seconds in a day. If the number of seconds entered by the user is greater than or equal to 86400, the program should display the number of days in that many seconds.• There are 3600 seconds in an hour. If the number of seconds entered by the user is less than 86400, but is greater...

  • Write a program that asks a user to enter a number to echo it out For...

    Write a program that asks a user to enter a number to echo it out For example : Enter a number : "write the number here" You entered : "the number you wrote up their^ Also make sure to write comments, Use the MIPS assembly language

  • Can you write with comments please. Thank you. Write a Java Program that asks the user...

    Can you write with comments please. Thank you. Write a Java Program that asks the user to enter the responses on the Console and write the responses to a text file called responses.txt (in the same directory as the program) Write another JAVA prorgram to read responses.txt file and calculate the frequency of each rating in the file and output the number and frequency in two columns (number, frequency) on the Console.

  • Write a program that asks the user to enter number, and displays all the numbers that...

    Write a program that asks the user to enter number, and displays all the numbers that are multiples of 2 and 5 smaller than or equal to the number entered by the user. Hint: A number n is a multiple of 2 if the remainder of the division of n by 2 is equal to zero. Your program should have an output similar to the following: Please enter a number: 50 The multiples of 2 and 5 less than or...

  • Write a program that asks the user to enter a string and then asks the user...

    Write a program that asks the user to enter a string and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the string. python programming

  • 1. Write a program that asks the user to enter two integers, obtains the numbers from...

    1. Write a program that asks the user to enter two integers, obtains the numbers from the user, then prints the larger number followed by the words “is larger.” If the numbers are equal, print the message “These numbers are equal.” Use only the single-selection form of the if statement you learned in this chapter.

  • Write one complete C program that asks the user for a floating point number and displays...

    Write one complete C program that asks the user for a floating point number and displays the absolute value of the number with two decimals of accuracy. You are not allowed to use the abs or fabs functions.

  • Write a program that asks the user to enter 1000 integers to be stored in an...

    Write a program that asks the user to enter 1000 integers to be stored in an array called "numbers". Since the same integer might occur (exist) in the array multiple times, your program needs to fill a second array, called "Isolate" that contains all the integers from the first array but NOT REPAPTED (every integer will exist only once). Finally, your program will print the integers of the second array sorted by occurrence (occurrence is: the number of times the...

  • Write a program that asks the user to type an even number or 111 to stop....

    Write a program that asks the user to type an even number or 111 to stop. When the user types an even number, display the message “Great Work”, and then ask for input again. When the user types an odd number, display the message “Try again” and ask the user to enter again. When the user enters the sentinel value of 111 the program ends I've attempted this but it went horribly wrong. we are only suppose to use while,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT