Some C++ Code
Posted: March 18th, 2004, 3:27 am
Code: Select all
#include <iostream.h>
int roundup(double num);
int main(int argc, char *argv[])
{
int q[12], c = 0, temp, max = 20;
double temp2 = 0.0;
char qx[50];
char a = 'Y';
while (a == 'Y')
{
system("clear");
cout << "QUANTITIES: ";
for (int i = 0; i<=49; i++)
qx[i] = " ";
cin >> qx;
c = 0;
for (int i = 0; i<=11; i++)
q[i] = 0;
for (i=0; i<=49; i++)
{
if (qx[i] == 47)
c++;
else if ((qx[i] >= 48) && (qx[i] <= 57))
q[c] = q[c] * 10 + qx[i] - 48;
}
temp = max = 20;
for (i=0; i<=11; i++)
{
if (q[i] > temp)
temp = q[i];
}
max = temp - (temp % 20) + 20;
if (temp % 20 == 0)
max -= 20;
for (i=0; i<=11; i++)
{
temp2 = max / 20;
q[i] = roundup(q[i] / temp2);
}
for (i=20; i>=1; i--)
{
cout << i % 10 << " ";
for (c=0; c<=11; c++)
{
if (q[c] >= i)
cout << "X";
else
cout << " ";
cout << " ";
}
cout << "\n";
}
cout << "SCALE = 1 : " << max / 20 << "\n";
cout << "ANOTHER GRAPH (Y/N)? ";
cin >> a;
}
return 0;
}
int roundup(double number)
{
int a;
a = number;
if (a < number)
{
a++;
return a++;
}
else
{
return a;
}
}