rectangle

Nov 18, 2019 at 1:24pm
EDIT: It appears the OP has swum away.

Can someone write the whole cod please?

There's something "fishy" about this!

Ah, yes, seen this post before. http://www.cplusplus.com/forum/beginner/265416/#msg1143024

@Reshgod
(1) please don't double-post: it prompts ire rather than code;
(2) it's not the most difficult assignment under the sun - please have a try first.
http://www.cplusplus.com/doc/tutorial/control/#for
Last edited on Nov 18, 2019 at 3:58pm
Nov 18, 2019 at 2:19pm
This should be close to what you asked for. Such simple starter programs (typically < 10 total lines) I will help with but you need to start trying and learning or you will soon ask things I refuse to help with.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
using namespace std;

int main()
{
 int a,b;
 cin >> a >> b;
 for(int i = 1; i <=a*b; i++)
 {
   cout << (i%b ? "x" :"x\n");     	 
 }
    if(a!=1&&b!=1)
      cout<<  a + a-2 + b-1+b-1 << endl;
    else
      cout << a*b << endl;
}


while you are working on it you can double check my perimeter count logic. I think it works but I only tested a few basic cases. Whole thing goes wrong if you type in negatives / junk of course. It works for 1x1, 1x2, 2x1, and 2x2 and bigger as far as I can tell.
Last edited on Nov 18, 2019 at 3:29pm
Nov 18, 2019 at 3:56pm
We could write the program for you, but that would not help you to learn.
Nov 18, 2019 at 3:59pm
kids these days. Even when you give them the code, they still get all worked up.
Nov 18, 2019 at 4:40pm
I wouldn't mind, @Jonnin, but I'd written everything he asked for!

Reshgod wrote:
Can someone write the whole cod please?
Reshgod wrote:
I must use for.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <cmath>
using namespace std;

double fish( int x )
{
   double xx = ( x - 16 ) * ( x - 16 );
   return abs( x < 16 ? sqrt( 64.0 - xx / 4.0 ) : 8 - 0.01 * xx );
}

int main()
{
   for ( int j = 8; j >= -8; j-- )
   {
      for ( int i = 0; i < 56; i++ ) cout << ( abs( j ) <= fish( i ) ? '*' : ' ' );
      cout << '\n';
   }
}


                *                                       
         ******************                            *
      *************************                       **
    ******************************                   ***
   **********************************              *****
  *************************************           ******
 ****************************************       ********
 ******************************************   **********
********************************************************
 ******************************************   **********
 ****************************************       ********
  *************************************           ******
   **********************************              *****
    ******************************                   ***
      *************************                       **
         ******************                            *
                *                                       

Nov 18, 2019 at 5:14pm
ROFL!

OK, lastchance, you won the internet today.
Nov 18, 2019 at 6:01pm
Nice! I started to do a fish, I saw the cod thing, then my mind found other ways to use that word, and I gave in and just drew a rectangle to be safe.

That code to do the fish is outstanding!
Last edited on Nov 18, 2019 at 6:02pm
Nov 18, 2019 at 6:27pm
That’s awesome!
Nov 19, 2019 at 1:33am
That fish code is so cool I bookmarked the post.
Topic archived. No new replies allowed.