Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This code prints an arrow using '*'. Could somebody help me on how I could also account for the length of the arrow from tail to point? Using C++ in Visual Studio 2013

C#
#include <iostream>
#include <sstream>


void draw_arrow(int width, int tail, char draw){
//print head
for(int i = 1; i <= width; i+=2){
//print spaces
for(int j=0; j<(width-i)/2; j++)
std::cout << " ";
//print chars
for(int j=0; j<i; j++)
std::cout << draw;

std::cout<<"\n";
}
//print tail
for(int i = 0; i < width/2; i++){
for(int j=0; j<(width-tail)/2; j++)
std::cout << " ";
for (int j=0; j<tail; j++)
std::cout << draw;
std::cout << std::endl;
}


}

int main()
{
int width_of_arrow = 0;
int width_of_tail = -1;
char drawing_char = '\0';
std::string input;
std::cout << "Input Width of Arrow: ";
std::getline(std::cin, input);
std::stringstream(input) >> width_of_arrow;

std::cout << "Input Width of Tail: ";
std::getline(std::cin, input);
std::stringstream(input) >> width_of_tail;
if (width_of_tail == -1) width_of_tail = 1;

std::cout << "Input Drawing Character: ";
std::getline(std::cin, input);
drawing_char=input[0];
if (drawing_char == '\0') drawing_char = '*';

draw_arrow(width_of_arrow, width_of_tail, drawing_char);
return 0;
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900