C# :: How To Draw A Square Within A Square

Oct 25, 2013

I know how to draw a square hollow or filled but I need to draw an alternating pattern

ex
iPatternHeight = 1
X

iPatternHeight = 3
OOO
OXO
OOO

[Code] ......

View 2 Replies


ADVERTISEMENT

C++ :: Draw A Square Within A Square Pattern

Oct 25, 2013

I know how to draw a square hollow or filled but i need to draw an alternating pattern ....

ex
iPatternHeight = 1
X

iPatternHeight = 3
OOO
OXO
OOO

[Code] .....

View 6 Replies View Related

C/C++ :: How To Draw A Square Based On User Input

Nov 5, 2014

Okay so I have to draw a square using "c" that draws according to the user input. Also, this has to be a function, and here is the code I have so far:

#include <stdio.h>
void DrawSquare(int length, char symbol);
void DrawSquare(int length, char symbol) {
int row;
int col;

[Code] .....

When I run this program it compiles fine but when the user input is recorded it just draws nothing but makes tons of spaces.

View 2 Replies View Related

C/C++ :: Trying To Draw A Grid In A Square For Simple Checkers Game

Oct 7, 2014

I am trying to draw a grid for checkers. I could draw a square at the starting point from origin with the code below(attached the pic below how it looks) however I am not being able to draw a grid when the program runs.

#include "ccc_win.h"
// GameDemo.cpp
// Shows how to place a piece accurately on a grid after a mouse click.
#include "ccc_win.h" // for graphics classes and functions
using namespace std;
int ccc_win_main(void) // main function for graphics program

[Code] ....

View 3 Replies View Related

C/C++ :: Displaying Filled Square Next To Hollow Square?

Feb 28, 2015

I am able to display a filled and hollow square by themselves, but I can't seem to be able to get them side by side.

So this is my code so far:

[/
#include <iostream>
using namespace std;
int main()

[Code]....

I can get the hollow square to show up, but the first square just shows up as a single line instead of a square. It seems that it ignores the first if statement in the second loop. I've tried not using an if statement in the second loop but it didn't seem to work either.

View 4 Replies View Related

C/C++ :: Can't Get The Right Square Pattern

Jul 4, 2014

I've been working on this code that should be looking like

1 3 5 3 1
3 5 7 5 3
5 7 9 7 5
3 5 7 5 3
1 3 5 3 1

but mine appears like this

1 3 5 3 1
3 5 7 5 3
5 7 9 7 5
3 3 5 7 9
1 3 1 3 5

This is the code I've got for now, I just don't know which logic I need to fix

int main(){
int r;
cout << "Rows?" << endl;
cin >> r;
for (int i = 1; i <= r; i+=2){
for (int j = i; j <= r+i; j+=2){
cout << j<< " ";
} for (int k = i+2; k >= i-1; k-=2){

[code]....

View 2 Replies View Related

C++ :: Square Root Of Number

Dec 9, 2013

i have written a function that gives me the square root of a number. Yes i know there is already a function in <cmath> that gives square roots but i thought it would be pretty challenging (and therefore fun) to try writing one on my own. I wrote my code while i was in school, listening to my Irish teacher ramble on and on about useless shit, so it's probably not the best possible way of finding the square root of a number.

double msqrt(double x) {
double adder=1;
double y = x;
for(int a=0; ; a++) {
if(y*y > x) y = y/2;
if(y*y <= x) break;

[code]....

View 6 Replies View Related

C++ :: How To Move Square To The Left

Apr 20, 2013

Having trouble getting my square to move to the left my code and instructions of what i am suppose to do is below. No sure how to move my square or if I am even going in the right direction as to writing code to do so. Note that it is only part of my code ( part 2 of project)

Part 2:

Write a graphical application that draws a square and then moves it.

Get the x and y coordinates for the top left corner of the square from the user using the get_int() member function of cwin. Get the length of a side of the square from the user using get_int() as well. Now draw the square to cwin according to the user input.Ask the user how many units to the left they want to move it using get_int() again. Then move the square, clear the screen, and draw it again.

// Part 2 //
/* command output to declare the x,y value and 1 side length of a square through user interaction( Has user input intergers) */
int x_value = cwin.get_int("What is the x_value of the top left of the square?");
int y_value = cwin.get_int("What is the y_value of the top left of the square?");
int side_length = cwin.get_int("Input the length for one side of the square:");
/* Data type for the 4 corners of the square */
Point e;
Point f;

[Code]...

View 2 Replies View Related

C# :: Creating A Magic Square

Feb 5, 2015

My university assignment requires us to create a magic square. The definition of which can be found on Wikipedia and such, but essentially it's a (n) times (n) grid where all the row, column and diagonal totals meet the formula [n(n2 + 1)]/2. So a 3x3 would provide totals of 15 for example.

It's been requested that we use brute force for this, nothing mathematically fancy. I've succeeded in the task and initially during testing was coming up with a result of a 3x3 magic square after between 10 million and 1 billion attempts over a few minutes to nearly an hour.

I proceeded to refine my code and have as little as possible in the while loop which I'd break out of once the function had found a magic square, nothing really made much difference until I moved the declaration of my random to just before my while loop instead of within.

Random RanGenerator = new Random();

Once I'd done this I was getting 3x3 magic squares after a few thousand iterations in less than a second, which has completely baffled me. I can understand if it would save time, but how could that reduce the amount of attempts required to solve the magic square?

View 6 Replies View Related

C++ :: MFC Drawing Circle Instead Of Square

Mar 11, 2014

Found a good beginner's tutorial to learn Visual C++: [URL] ....

How to change the drawing so that instead of squares, the game draws circles. Can figure out that using Ellipse in the code results in circle outlines, but the fill remains as square color shapes.

The drawing code from the tutorial is below. How to substitute filled circles for filled squares.

Code:

// CSameGameView drawing
void CSameGameView::OnDraw(CDC* pDC){
// First get a pointer to the document
CSameGameDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if(!pDoc)

[Code] ....

View 6 Replies View Related

C :: Drawing A Shape (Square) Into PGM Image

Nov 22, 2013

I'm doing a project and I need to draw a square into a pgm image if certain conditions are met, but I'm not sure how to draw the square into the image.

View 2 Replies View Related

C :: How To Reflect A Square Matrix Diagonally

Jun 10, 2013

I have progressed to a point but I don't know what have I done wrong.

Code:

#include <stdio.h>#include <conio.h>
int main () {
int i, j, n, temp;

[Code].....

View 5 Replies View Related

C++ :: Display Remainder Of The Square Of Numbers From 100 To 10

Mar 31, 2013

Display the remainder of the square of numbers from 100 to 10. This square of numbers must be divisible by the numbers from 100 to 10 respectively. what i need to in this

View 3 Replies View Related

C++ ::  Calculating Sum Of Square Of Numbers Between Two Inputs

Mar 28, 2014

Write a function which takes two parameter of integer type and both parameters are positive integer. These number should be provided by the user of your program. The first parameter is lower than the second parameter. You function should be able to calculate the sum of the square of each of the numbers between the two inputs and should display that. Please write a main function to display the working of your function. Call the function at least three times by using some loop in the main function.

This is what I came up with but it is not correct:

#include <iostream>
using namespace std;
void sumsquares(int number1, int number2) {
int sum = 0;
for(int i = number1; i<number2; i++)
sum =sum+ i*i;
cout<<"The Result is: "<<sum<<endl;

[Code] .....

View 2 Replies View Related

C++ :: How To Square And Cube Number In Program

Feb 18, 2014

#include <iostream>
#include <conio.h>
#include <iostream>

[Code].....

I can't find a way to square and cube the number I want, which the number will show in the notepad. Is there a way to cube and square a number in my program??

View 5 Replies View Related

C++ :: Printing Square Free Numbers?

Feb 27, 2014

I'm currently trying to write a program that takes an integer input from the user and displays that number of square-free numbers. I've gotten most of the program to work, but I encounter an error during the noSquare function that causes it to print incorrectly.

A square-free number is a number that is not evenly divisible by the square of any prime number. It's hard to see the bold in the code area, but it begins after the "//I think below is where the problem is"

#include <iostream>
#include <vector>
using namespace std;

[Code]........

View 1 Replies View Related

C/C++ :: 3x3 Magic Square That Sums Up To 15 On All Sides

Mar 10, 2015

I have an assignment that I have to make a 3x3 magic square that sums up to 15 on all sides. I can't use arrays, just Loops and If and Else statements.

My first attempt was like this

//Program for printing magic square that sums up to 15.

#include <iostream>
using namespace std;
int main() {
int a, b, c, d, e, f, g, h, i;
int r1, r2, r3;
int c1, c2, c3;

[Code] .....

I can't think of a way to loop that when it prints out, it will have a sum of 15 on all sides and/or print one of the 8 solution for a 3x3 magic square.

View 3 Replies View Related

C/C++ :: 2D Arrays Function - Largest Square?

Mar 25, 2015

In this assignment, you are required to write a function called largest square. Your function should take a 2 dimensional array, 2 integers which represent the number of rows and columns in the array, and prints out a 2 X 2 array which represents the largest square in the array. The largest square means the square for which the sum of its elements is the greatest in the array. Submit your function in a file called largestSquare.c

Example: Given the array 1 2 3 4

5 6 7 8

9 10 11 12 the output should be 7 8

11 12

Example 2: Given the array 8 2 6

3 7 3

6 1 1 the output should be 8 2

3 7

The prototype of your function is void largestSquare(int[rows][columns], int rows, int columns).

Am I anywhere close with what I've started?

//
// main.c
// largestsquare
//

#include <stdio.h>
#include <stdlib.h>
int main(int argc, const char * argv[]) {
int rows, columns;

[Code] ...

View 5 Replies View Related

C/C++ :: Printing Square Free Numbers

Feb 27, 2014

I'm currently trying to write a program that takes an integer input from the user and displays that number of square-free numbers. I've gotten most of the program to work, but I encounter an error during the noSquare function that causes it to print incorrectly. I have bolded the area where I believe the problem is what I am doing wrong.

The problem with the program is that it prints ALL numbers from 1 to the input number instead of just the square-free.

A square-free number is a number that is not evenly divisible by the square of any prime number ....

#include <iostream>
#include <vector>
using namespace std;
bool noSquare (int num); //Function to determine if the number is square-free
vector<int> getPrimes(int num); //Function to get a vector of all primes below num
bool isPrime (int number); //Function to determine if individual numbers are prime
int main()

[Code]...

By the way, the in the middle of the code was me trying to bold a section, not an actual part of the code. I can't seem to find where to edit my original post.

View 3 Replies View Related

C/C++ :: Make Program To Square Numbers From 1 To 20

Oct 21, 2012

I want to make program to square the numbers from 1 to 20. i have written this program, it's running but not giving the required answer.i think it is giving a garbage value...

void main(void)
{int a;
  int  b;
b=a*a;
for (a=1; a<21; a++)
{printf("%d",b);
printf("the square is%d=b");
}
getche();}

View 2 Replies View Related

C++ :: Program To Find Transpose Of Given Square Matrix

Mar 24, 2013

I want to find transpos of square matrix.but my program does not run complete.

Code:
#include<iostream>
using namespace std;
const int size=3;
void read(int a[size][size])

[Code] .....

View 2 Replies View Related

C :: Program To Find The Square Root Of A Number

Dec 5, 2013

I am writing a program to find the square root of a number. I am using the Newton-Raphson method..Just to clarify a bit of the code.. fabs(1/(x+1)) < 0.001 is to check for relative error..

EXAMPLE: for user entry of 100 if the iteration process ends in 10.055 the answer will return as 10 which is correct. But it isn't doing that.

It compiles I then proceed to run it..prompts me "Enter a number to find the square root of: I type 100 then hit enter...

"The square root of 100 is -1077834936"

My first time writing a program from complete scratch.

And I know there is a sqrt() function...just wanted to write my own.

Code:

#include <stdio.h>
#include <math.h>
double mysqrt(double a);
int main()
{
double a, result;
printf("Enter a number to find the square root of: ");

[Code]...

View 1 Replies View Related

C :: Prototype Function Square Root Velocity

Mar 30, 2013

I am trying to computed the time it takes for a projectile to hit the ground. The problem is that i need to square the input of velocity before i do the calculation. the question I have is that if it's possible to have multiple arguments inside the brackets after main.

#include <stdio.h>
#include <math.h>
double distance (double a, double v, double g);
int square(int y);
double height(double v, double a, double g);
double time (double v, double a, double g);
double sqrt(double num);

[Code] ....

View 2 Replies View Related

C++ :: Find Area Of Room In A Given Square Maze

Apr 1, 2013

Area of the room. Your task is to write a program that will find the area of room in a given square maze.

Note. Use recursion for solving this problem.

Input:
First line contains only one number N (3 <= N <= 10).The number that describes the size of the square maze.
On the next N lines maze itself is inputed ('.' - empty cell,'*' - wall).
And the last line contains two numbers - the row and column of the cell in the room those area you need to find.It is guaranteed that given cell is empty and that the maze is surrounded by walls on all sides.

Output:
Output only one number - total amount of empty cells in the selected room.

View 8 Replies View Related

C++ :: Detect Mouse Position - Square Shape

Jul 16, 2013

I am trying to detect when my mouse is over a item. I can get it working if its a square shape an stuff.

(LOWORD(lParam) > 133) && (LOWORD(lParam) < 154) && (HIWORD(lParam) > 0) && (HIWORD(lParam) < 21)

but how would i detect if its over the white spot in this image? [URL] ....

i just drew a simple shape i need to detect from more edges but how to do it?.

View 7 Replies View Related

C++ :: Program That Will Ask User To Enter Area Of Square?

Feb 11, 2013

B. Circle in a Square Write a C++ program that will ask the user to enter the area of a square. Then the program will display the biggest area of a circle that will fit in a given square. Using math.h library is not allowed.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved