User enters one number with word example: three. Possible entries are numbers from one to nine. Write out words(numbers) in seperated lines. In every seperate line add one more word(number). Seperate numbers with comma.
example:
User enters five.
Output should look like:
five
five, five
five, five, five
five, five, five, five
five, five, five, five, five
User enters three:
three
three, three
three, three, three
Can you help me solve this problem. I've got and idea but i don't know how to write it down.
For instance:
I would count lenght of the word in one word(number). Possible lenght in letters would be 3, 4 and 5. Example: one has three letters. Four has 4 letters. Seven has 5 letters. With this i can eliminate all other entries. But i don't how would i compare later entry with the possible numbers.
usingnamespace std; is not a library. It just tells the compiler that you're going to be using some symbols defined in the std namespace. Things like string, cout, and endl are all things that exist in the std namespace. I didn't have to declare anything named cout, I just use cout. If you say usingnamespace std;, you don't have to put std:: in front of string, cout, and endl.
break; makes the program jump out of the current loop. If I find a match, I don't want to keep looking, so I break out of the for loop.
The loop matches a string to a lookup value. That's how I get an integer 7 from the string "seven".
You are not using the for loop properly. You have created an infinite loop that doubles the size of a string every time it executes. Eventually, you run out of memory and your program can no longer allocate new memory. That's what bad_alloc means.
But i dont know what should i do that instead of ", seven" I could write something else because if i write someStringFromUser again then program just gets out of control.
int i=0;
for(;i < intVersionOfUserInput;)
{ cout<<someStringFromUser<<endl;
someStringFromUser=someStringFromUser+number;
i=i+1;
}
is more eloquently expressed like this:
1 2 3 4 5
for (int i = 0; i < intVersionOfUserInput; i = i + 1) //i = i + 1 can be replaced with i++
{
cout<<someStringFromUser<<endl;
someStringFromUser=someStringFromUser+number;
}
The goal of your exercise is to get you to understand how to use nested loops.
1 2 3 4 5 6 7
for (int i = 0; i < intVersionOfUserInput; i++)
{
//print someStringForUser a certain amount of times using another for loop
//(Hint: it will be based on the current value of i)
//print a new line
}
Sorry but i dont understand what u meant with the exercise...
1 2 3 4 5 6 7 8 9 10 11 12 13
for (int i = 0; i < intVersionOfUserInput; i++)
{
//print someStringForUser a certain amount of times using another for loop
//(Hint: it will be based on the current value of i)
for(;;)
{
cout<<someStringForUser;
cout<<endl;
}
//print a new line
}