The base of this code was provided by my professor and he simply said to debug the program. I have made many changes already so this is not the original code provided but what I currently have left to fix. Any help/explanation would be appreciated.
// Diamond.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
usingnamespace std;
int main()
{
cout << "Enter size of Diamond: ";
int size;
cin >> size;
int z = 1;
for (int i = 0; i <= size; i++)
{
for (int j = size; j > i; j--);
{
cout << " "; // printing space here
}
cout << "*"; // printing asterisk here
if (i>0)
{
for (int k = 1; k <= z; k++)
{
cout << "*";
}
z += 2;
cout << "*";
}
cout << endl; // end line similar to \n
}
z -= 4;
for (int l = 0; i <= size - 1; i++)
{
for (int j = 0 j <= i; j++)
{
cout << " ";
}
cout << "*";
for (int k = 1; k <= z; k++)
{
cout << "*";
}
z -= 2;
if (i != size - 1);
{
cout << " ";
}
cout << endl << endl;
}
return 0;
}
I just emailed my professor since he unfortunately did not specify. I am not sure if it is my job to figure out what the program is supposed to accomplish but I feel like it should have been stated, otherwise all the students could turn in a drastically different program that accomplishes different things. I will let you know what he replies as soon as I find out. Thank you for your reply.
I am running this code through visual studio and get many syntax errors that look like "missing ')' before '<=' ". But then when I add the character that it says I am missing, that doesn't fix the problem, the red error underlining the words remains in place. I also do not seem to understand what it means by "i/j is unidentified". When I google those error messages, I get hundreds of possible reasons as to why the program might say that. Again, thank you everyone for your time.
I too us VS. You will find that the line number listed is not always where the error is. Some times a missing ; on one line will affect many lines after the problem or even the rest of the program. Even a problem in a for loop in what is between the (), oops I should not have said that, can, as we see, cause many errors that have nothing to do with the original problem.
There are only two problems that need to be corrected and they are not easy to find. That is why you have to know how to write an if statement, while loop, do/while loop and for loops to spot some of these problems.
If I remember correctly one missing item caused 26 errors and each line and problem listed was not actually a problem because the error was above where the 26 errors started.
My professor emailed my back today to and said that the program's output should look like:
*
***
*****
*******
*********
*******
*****
***
*
Something like this or a "hollow" version of this where its just the outline.
(when writing this response the diamond looks entirely different than what it does after its posted. It should have 4 corners, not just 3 like it does when this is posted.)