norbert90

1)Write a C++ program that prints a capital C of Stars. The user should be allowed to enter the width, the height and the thickness of the shape.
2)Write a C++ program that reads positive integers and calculates and prints the number of odd and even digits in each.The program should terminate once a negative integer or a zero input.
3)

``````int rows=3;
int cols=5;
for(int a=1;a<=rows;a++)
{
for(int b=1;b<=cols;b++)
cout<<a*b<<" ";
cout<<endl;
}``````

Rewrite the code segment above using while loops instead of for loops.

Nick Evan 4,005

So what have you done so far?

norbert90

So what have you done so far?

1)I don't know what is wrong here, when executed, the letter Capital C of stars isn't clearly showed.

``````#include<iostream.h>
int main(){
int h,w,t;
cout<<"Enter the height: ";
cin>>h;
cout<<"Enterthe width: ";
cin>>w;
cout<<"Enter the thickness: ";
cin>>t;
for(int i=1;i<=w;i++)
{
for(int j=1;j<=h/2-1;j++)
cout<<"*";
cout<<endl;
}
for(int k=1;k<=t;k++)
{
for(int l=1;l<=t-1;l++)
cout<<"*";
cout<<endl;
}
for(int e=1;e<=w;e++)
{
for(int e=1;e<=h/2-1;e++)
cout<<"*";
cout<<endl;
}
return 0;
}``````

Let me see if I get your objective correct. You want an application that takes 3 int inputs, h, w and t and creates a "C" in *s where h is the total height, w is the width for the top & bottom parts and t is the thickness which determines both height and width for the center piece?

If so, your for loops are nested backwards and your loop count is wrong.

The nesting should look more like:

``````for(int i = 0; i < h / 2; i++)
{
for(int j = 0; j < w; j++)
{
cout << "*";
}
cout << endl;
}``````

You'll need to loop the number of times of height / 2, then loop the width for spelling out *s, where you currently have it looping width, then height / 2. This goes for the bottom half too. Your center piece is right, as long as my assumption of what you want is right. If not, please give an example of expected output.

Counting should look like this (at least for this application)

``for(int i = 0; i < w; i++)``

Also, as another tip, variables defined in for loops go out of scope when the loop ends, so you can use int i & int j for each nest, rather than picking from all over the alphabet. It's a bit cleaner.

norbert90

Let me see if I get your objective correct. You want an application that takes 3 int inputs, h, w and t and creates a "C" in *s where h is the total height, w is the width for the top & bottom parts and t is the thickness which determines both height and width for the center piece?

If so, your for loops are nested backwards and your loop count is wrong.

The nesting should look more like:

``````for(int i = 0; i < h / 2; i++)
{
for(int j = 0; j < w; j++)
{
cout << "*";
}
cout << endl;
}``````

You'll need to loop the number of times of height / 2, then loop the width for spelling out *s, where you currently have it looping width, then height / 2. This goes for the bottom half too. Your center piece is right, as long as my assumption of what you want is right. If not, please give an example of expected output.

Counting should look like this (at least for this application)

``for(int i = 0; i < w; i++)``

Also, as another tip, variables defined in for loops go out of scope when the loop ends, so you can use int i & int j for each nest, rather than picking from all over the alphabet. It's a bit cleaner.

Sample output:
Enter the height: 11
Enter the width: 14
Enter the thickness: 4

**************
**************
**************
**************
****
****
****
**************
**************
**************
**************
Press any key to continue

waziryx

hi hlp me with problem

norbert90

Let me see if I get your objective correct. You want an application that takes 3 int inputs, h, w and t and creates a "C" in *s where h is the total height, w is the width for the top & bottom parts and t is the thickness which determines both height and width for the center piece?

If so, your for loops are nested backwards and your loop count is wrong.

The nesting should look more like:

``````for(int i = 0; i < h / 2; i++)
{
for(int j = 0; j < w; j++)
{
cout << "*";
}
cout << endl;
}``````

You'll need to loop the number of times of height / 2, then loop the width for spelling out *s, where you currently have it looping width, then height / 2. This goes for the bottom half too. Your center piece is right, as long as my assumption of what you want is right. If not, please give an example of expected output.

Counting should look like this (at least for this application)

``for(int i = 0; i < w; i++)``

Also, as another tip, variables defined in for loops go out of scope when the loop ends, so you can use int i & int j for each nest, rather than picking from all over the alphabet. It's a bit cleaner.

It works and I am fine now. Thanks a lot Sir! I really appreciate your help.
Can you help with the second and third problems?