PhoenixTilea
Member
Hey, guys. I need some debugging help...
I'm trying to finish up a project, and I have NO idea why this program isn't working. There aren't any actual bugs in it, just a logical error apparently....
Okay, what this program is supposed to do is print a diamond on the screen based on a width and composition character the user provides.
So, output for this should look something like:
But, what the program actually does is takes the width and character from the user... and then ends. Even if the for loops aren't running properly, it should AT LEAST print that last line in the main loop, but it just ends... I can't figure it out...
Anyone have any ideas...?
I'm trying to finish up a project, and I have NO idea why this program isn't working. There aren't any actual bugs in it, just a logical error apparently....
Code:
Â
//The Diamond Printer
Â
#include <iostream>
using namespace std;
Â
char charToPrint = ' ';
int diaWidth = 0;
int space = 0;
int printing = 0;
Â
void getWidth();
void getCharacter();
Â
int main()
{
  cout << "Welcome to the Diamond Printer!" << endl;
  cout << "By Sabelyn Thorpe" << endl;
  getWidth();
  cout << endl;
  getCharacter();
  cout << endl;
  for (int i = 1; i <= diaWidth; i +=2) {
    space = (diaWidth-i)/2;
    do {
      cout << " ";
      space-=1;
    } while (space > 0);
    printing = i;
    do {
      cout << charToPrint;
      printing -= 1;
    } while (printing > 0);
    space = (diaWidth-i)/2;
    do {
      cout << " ";
      space-=1;
    } while (space > 0);
    cout << endl;
  }
  for (int i = diaWidth-2; i >= 1; i -=2) {
    space = (diaWidth-i)/2;
    do {
      cout << " ";
      space-=1;
    } while (space > 0);
    printing = i;
    do {
      cout << charToPrint;
      printing -= 1;
    } while (printing > 0);
    space = (diaWidth-i)/2;
    do {
      cout << " ";
      space-=1;
    } while (space > 0);
    cout << endl;
  }
  cout << endl << "Thanks for printing!";
}
Â
void getWidth()
{
  do {
    cout << "Enter the width of your diamond: ";
    cin >> diaWidth;
    if ((diaWidth <=23) && (diaWidth>=1)) {
      if (diaWidth%2==0) {
        diaWidth = diaWidth+1;
      }
    }
    else {
      cout << "Please enter a number from 1 to 23.";
    }
  } while ((diaWidth <= 1) || (diaWidth >= 23));
  return;
}
Â
void getCharacter()
{
  cout << "Enter a character to print: ";
  cin >> charToPrint;
  return;
}
Â
Okay, what this program is supposed to do is print a diamond on the screen based on a width and composition character the user provides.
So, output for this should look something like:
Code:
Â
Enter the width of your diamond: 7
Enter a chacter to print: *
Â
  *
 ***
 *****
*******
 *****
 ***
  *
Â
But, what the program actually does is takes the width and character from the user... and then ends. Even if the for loops aren't running properly, it should AT LEAST print that last line in the main loop, but it just ends... I can't figure it out...
Anyone have any ideas...?