1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
#include <iostream>
#include <cmath>
using namespace std;
void inp(int& width, int& space, int& star, double& width2);
void outp(int& width, int& space, int& star, double& width2);
int main()
{
char cont = 'y';
int width, space, star;
double width2;
do//do-while loop allows program to be run multiple times
{inp(width, space, star, width2);
outp(width, space, star, width2);
cin >> cont;}
while(cont == 'y' || cont == 'Y');
return 0;}
void inp(int& width, int& space, int& star, double& width2)//***INPUT***
{
cout << "Enter the width of a diamond shape and I will output that diamond in asterisks.\n";//prompt
//Take 'width'
cin >> width;
while(width <= 0)//edge case if unitprice is less than 0
{cout << "The width must be a positive number. Try Again.\n";
cin >> width;}
while(width % 2 == 0)
{cout << "The width must be an even integer. Try Again.\n";
cin >> width;}
width2 = width;}
void outp(int& width, int& space, int& star, double& width2)//***OUTPUT***
{
for(star = 1; star <= width; count++, space = (width2 / 2) - (star / 2))
{cout << space << star << space;
cout << "Do you want to continue? < 'y' or 'n' >: ";}}.
|