C :: Drawing A Box With Coordinates - Printing Between Certain ASCII Values
Sep 23, 2014
The assignment is:
1) Write a program that asks the user for a a single character and two XY coordinates. The two X and two Y values should all be integers between 0 and 50. The character should be a printable ASCII character with values between and including ' !' (ascii value 33) and '~' (ascii value 126).
2) Your program should then draw a rectangle made up of the user selected character where the upper left corner is at X1; Y 1 and the lower right corner is at X2; Y2. Be sure to print the appropriate number of blank lines (having spaces in the blank rows is OK) in the beginning and pad each row of your rectangle with X1 leading spaces.
The Output is supposed to be similar to this:
(X1,Y1) = (0,0) , (X2,Y2) = (4,4), the character = ^
^^^^
^^^^
^^^^
^^^^
What I am having trouble understanding is printing between certain ASCII values (ASCII has never been discussed in class).
Another thing I am having trouble with is the main part of the assignment. From what we are currently discussing is loops and the assignment is covering nested loops. My code looks similar to this:
Code:
#include <stdio.h>
int main (void) {
int X1, Y1, X2, Y2;
char cRec;
printf("Enter a character: ");
scanf("%c", &cRec);
[Code] .....
My thinking on the assignment is that you want the X1 coordinate to increase to the value of X2 (same for Y1 and Y2). Is this thinking wrong?
View 12 Replies
ADVERTISEMENT
Apr 24, 2015
For a Texas holdem' project I need to be able to draw out rectangles using ASCII codes and for loops. I started the code
#include <iostream>
#include <string>
#include <Windows.h>
[Code].....
View 6 Replies
View Related
Apr 9, 2014
I'm trying to write a program which prints a table of ASCII chars, I'm not really done with my thoughts on it but I already
ran into the following error:
Error: cannot initialize a variable of type 'char' with an rvalue of type 'char (*)[16]'
Here's my code so far:
# include <iostream>
using namespace std;
int main() {
char asciiTable = new char[8][16];
int nextSign = 0;
[Code] .....
View 4 Replies
View Related
May 21, 2012
I'm wanting to create an image, all I need is to be able to set RGB values and X-Y coordinates, I'm not wanting to read or manipulate images. Any easy to use library or another simple method of doing this?
View 1 Replies
View Related
Sep 1, 2014
New file_sorter.c:
#include <stdio.h>
#include <stdlib.h>
#include "sort.h"
#include <string.h>
[Code].....
My issue is now a segmentation fault in my sorting algorithm. In my assignment I was suppose to implement quick and insertion sort for the file, and organised strictly by ASCII values. We were allowed to look up generic algorithms for the sorts, but we have to convert them to comparing char arrays.
I haven't started trying to configure quick sort yet, but I'll supply the generic algorithm as well. keep in mind that the first line in the file contains the number of lines in the file. I'll try not to disappear this time!
sort.c :
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
[Code]....
View 4 Replies
View Related
Sep 23, 2013
This seems like a fairly straight forward assignment. Load up a file that contains a series of int values stored in ASCII and print out the ASCII characters to the console.
The problem I am having is that I am getting the numerical value of bytes ("40" for 10 numerical values, "200" for 50 values). The numbers are generated randomly by another file, but I can control how many numbers are generated. For example, if I type in:
shell% cat tempfile
the output is as follows:
/8?qE?. Y4?(T???a???%@
but when I try to run it with my program:
shell% ./intcat tempfile
the output displayed is:
40
Code:
#include <stdio.h>
#include <assert.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char *argv[]){
//check if arguments match
[Code] .....
View 10 Replies
View Related
May 10, 2013
This is a small program that reads a line from the screen, takes the ASCII values from the entered text, and edits it. Next, the ASCII values are reinterpreted (am i misspelling?) as text, and displayed. However, my final output has (allways?) at least 7 characters, even if you enter only one. I'm also trying to accomplish, that the part of the string which isn't filled, will be printed empty. In spaces.
compiled with -std=c99.
Code:
#include <stdio.h>
int main(){
int maxsize;
printf("How long is your message?
[Code] .....
View 6 Replies
View Related
Apr 17, 2014
Why does this generate an error:
Code: std::copy( vec.begin( ) , vec.end( ) , std::ostream_iterator<double>( " " , std::cout ) ); whereas this works fine:
Code: std::copy( vec.begin( ) , vec.end( ) , std::ostream_iterator<double>( std::cout , " " ) ); I know I can use this instead:
Code: for ( std::vector<double>::iterator it1 = vec.begin( ); it1 != vec.end( ); ++it1 ) std::cout << " " << *it1;
View 5 Replies
View Related
Apr 11, 2014
I need to print all the values in a square 2d array that are above the diagonal line. So if I have this 6x6 array for instance:
{0,0,0,0,0,0},
{1,1,1,1,1,1},
{2,2,2,2,2,2},
{3,3,3,3,3,3},
{4,4,4,4,4,4},
{5,5,5,5,5,5}
I'd have to print the elements in italics. I've tried this:
for (i = 1; i < a.GetLength(0); i++) {
for (j = i-1; j >=0; j--)
Console.Write("{0,-2}", a[i, j]);
Console.WriteLine();
}
with the array mentioned above but for some reason it keeps printing the elements BELOW the line, when I need it to print those above it. I know that for arrays we usually start loops with a value of 0 but seeing as there should be nothing to print at [0,0] I started the loop at 1.
View 2 Replies
View Related
Dec 1, 2013
I am trying to read hex data from a file (not just hex values in text format). I was able to read it (02 EC) with "fread" into an char before but I need to change the Hex value into an integer in decimal.
I already read about strtol but I would prefer reading the hex Value into an integer.
Here is my code so far:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
int itrack1[1];
int itrack2[1];
[Code] ....
View 11 Replies
View Related
Mar 21, 2013
So I'm doing a kind of banking system. Atm I've got the user able to create an account and set the balance of it, which is written to a .txt file. However, I would like the user to be able to enter their account no. and the program to cout the account info on the screen. I will be adding more to the program later, but until I work out how to search for values in a .txt file, and print out values on that line I'm a bit stuck.
Code:
Main.cpp -
#include <iostream>
#include "create_account.h"
#include <fstream>
using namespace std;
int menuin;
int main() {
create_account creataccObj;
[Code] .....
Sample .txt file -
// Account_no - Balance //
1001 140500
1002 150600
1003 18600
View 8 Replies
View Related
Apr 15, 2014
I'm taking a C++ computer science course right now, and one of the questions on my latest assignment is this:
"A partition of an integer n is a way of writing n as a sum of positive integers. For example, for n=7, a partition is 1+1+5. Write a program that finds all the partitions of an integer n using r integers. For example, all the partitions of n=7 using r=3 integers are 1+1+5, 1+2+4, 1+3+3, 2+2+3."
I've been struggling with this problem for a couple days now, and how to do it. I understand I need a recursive function to grab variables, and probably an array or vector to store them, but where to begin.
I've been reading documents on partition generating and the concept still eludes me, and any other questions on here or other programming sites using partitions don't seem to have a constraint on them.
View 2 Replies
View Related
Jul 1, 2014
Using a for loop, construct two 100 element arrays, x and y, such that element i of x stores the value sin(2*pi*i/100)) and the corresponding element of y stores cos((2*pi*i/100)). Print the values stored in the elements of x and y as you calculate them.
I have attempted to solve it but I'm not sure why the value 0 is only being printed, maybe I haven't assigned sin(2i/100)) and cos((2i/100)) to the arrays properly?
Code:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main () {
[Code] .....
View 3 Replies
View Related
Jan 18, 2013
I'm in the beginning stages of designing my first video game using SDL, and have run into a bit of an impasse. I attempt to draw the map using a simple tile function and nothing prints to the screen. I am going to attach the function itself.
bool Tile::draw_tiles ( void ) {
GV gv;
//Open the map
std::ifstream map ( "test.map" );
for ( int y = 0; y < GV::MAP_HEIGHT / 64; y++ ) {
for ( int x = 0; x < GV::MAP_WIDTH / 64; x++ ) {
[Code] ....
Extra notes:
1. Compiles fine.
2. No run time errors (this function returns true).
3. Apply surface is a function that takes an x and y value for position on the
map, an image, a screen to print it to, and a rectangle to cut out the image out of.
4. I did some bug testing and added another function to print the image SDLS_tiles by itself (its just a simple sprite map) after the map.close() function, and it worked fine.
View 1 Replies
View Related
Feb 25, 2014
I am working on a small game and I have the following problem. I need to get the colour of a particular position in an image. Say I'm given coordinates (5,5) I need the colour of the part in the image. I think I can do the colour picking myself, but I don't know how to point at coordinates inside the image.
View 3 Replies
View Related
May 3, 2013
i have to make an application called " paint " in c++ . It should facilitate user to draw different shapes using a mouse. Now the biggest hurdle i am facing is the usage of mouse .. what is the header file for usage of mouse ? i am using visual studio 2010 . the syntax is creating problems ..
View 1 Replies
View Related
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
Nov 5, 2013
Night now I'm working on part of a function that scans in two sets of coordinates. Is there a way I can scan both sets of coordinates in with the same scanf?
ex. scanf("%d%d%d%d," &destroyer_1, &destroyer_2, &destroyer_3, &destroyer_4)
but that didn't work...
Code:
printf("What are the first coordinates for destroyer:
");
scanf_s("%d%d", &destroyer_1, &destroyer_2);
gameboard[destroyer_1][destroyer_2] = 'd';
printf("What are the second coordinates for destroyer:
[Code] .....
View 5 Replies
View Related
Feb 4, 2014
I have studied function,array,stuctures,flow of control(XI class cbse syllabus). Now I want to know how to find coordinates of cursor position in c++.
View 2 Replies
View Related
Mar 26, 2013
I know how to find a specific number in a multidimensional array, but I don't know how to have a specific number and find its coordinates.
View 2 Replies
View Related
Jan 16, 2013
I use the AS/400 warehouse system, and I need to be able to automate typing one letter in several different locations to speed things up.
My thoughts are:
1. Find out how to make a program that will determine x, y coordinates of mouseclicks, and then use software to use macros to change information.
2. Build a program that will complete a single process by repeating set mouse clicks and keystrokes.
We recieve HUGE transfers from a warehouse across the country, and have to change the first character of the name of bin locations - and after a few pages it gets VERY tedious.
View 4 Replies
View Related
Dec 10, 2014
Below is what i have so far. My main issue is outputting the area and perimeter of the given coordinates as i need the final coordinate to connect up to the first coordinate. I've tried doing that using numberOfcorners but it says "the expression must have integral or enum type"
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <math.h>
using namespace std;
int main() {
float ArrayX[10];
float ArrayY[10];
float numberOfcorners;
[Code] .....
View 3 Replies
View Related
Jan 14, 2015
Essentially the problem is that when I click the mouse, the program doesn't seem to record the coordinates. So the if statements are never executed. The problem could also be with the if statements, I'm not sure.
One thing I noticed was that when the do while loop is running and the left mouse button is not pressed then X and Y of dwMousePosition are both 0. But then if I press the left mouse button then the coordinates become x = 1 and y = 0.
NOTE I'm on Windows 7, 64 bit, using Visual Studio Express 2013 for Windows Desktop
#include <iostream>
#include <windows.h>
#include <string>
#include <new>
#include <stdio.h>
using namespace std;
INPUT_RECORD ir[128];
DWORD nRead;
[Code] .....
View 1 Replies
View Related
Apr 7, 2014
I need to read x,y coordinates in text file using c++. The name of file is input.txt which is,
x y
232.1,753.7
100.5,981.6
96.2,992.9
148.7,953.2
197.2,999.3
249.9,998.6
261.7,975.9
262.4,905.8
334.9,980.8
371.6,979.4
396.7,996.3
405.1,995
565.5,766
459.4,988.5
474.4,994.6
594.6,996.8
604,987.3
612.8,877.3
664.1,992.6
#include <iostream>
#include <fstream>
using namespace std
struct monsters_struct {
int x, y;
[Code] ....
View 1 Replies
View Related
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
Oct 10, 2013
I am supposed to create a class of rectangular prism in opengl. I am having touble in writing my "draw()" function.
I have searched the web, and lots of the sites have:
glBegin(GL_Quads);
glVertex3f(x,y,z);
glVertex3f(...);
glVertex3f(...);
glVertex3f(...);
3D coordinates for each face.
For my code, I am getting a value for lengths of x, y and z like "getXlength(x_length)" etc... I would like to know how I can use these values to draw the prism rather than giving values for each coordinates in each face.
View 1 Replies
View Related