GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 27-Apr-2004, 09:31
warny_maelstrom warny_maelstrom is offline
Junior Member
 
Join Date: Jan 2004
Posts: 41
warny_maelstrom will become famous soon enough

Problems returning to main and closing the current box


Im creating a program to display a graph from the values inputted by the user(after various calculations), the thing is i want to be able to return to the original input screen after displaying the graph if the users likes. So basically I need to go back to "main" and close the previous box.
Iv created a button "Refresh" and this causes the box currently open to close but I have no idea how to return to "main".

[c]
#pragma windows 300000,500000,"cwp_ico.rc" //means dosbox is not displayed
#include<stdio.h>
#include<math.h>
#include<clib.h>
#include<windows.h>
#include<dbos\graphics.h>
#include<stdlib.h>

int help_switch=1;
float u=0, g, p, s, t, x0=0, y0=0, np=1;
int b4=0, b3=0, b2=0, b1=1, x1, x2, x3, x4, y1, y2, y3, y4, w1, w2, w3, w4, xmax=0, xmin=800, ymax=0, ymin=600, hand=0, ctrl,
c=0, n=2, col=0, wid=2, Draw(), Random(), Clear(), Refresh(), Close(), x2max, x2min, y2max, y2min;
short int x[100],y[100];//array with a maximum of 100 values
int main()
{
{
char hlp[]="Will input random values";//text displayed in help bubble
winio("%bg%ca[Data Input Screen]&",RGB(100,255,100));
winio("%fn[Arial]%tsEnter in 4 values for the x coordinates: \t%rd\t%rd\t%rd\t%rd\n&",1.2, &x1, &x2, &x3, &x4);
winio("Enter in 4 values for the y coordinates: \t%rd\t%rd\t%rd\t%rd\n&",&y1, &y2, &y3, &y4);
winio("Enter in 4 values for the weighting: \t%rd\t%rd\t%rd\t%rd\n&",&w1, &w2, &w3, &w4);
winio("Enter in the number of points to be on the line:\t\t\t\t\t\t%rd\n&",&n);
winio("Please choose a colour:\t\t\t%4`ga%rb[Red]\t\t%rb[Blue]\t\t%rb[Green]\t%rb[Purple]\n\n&",&b1,&b2,&b3,&b4,&b1,&b2,&b3,&b4);//4 radial buttons return boolean answers only one can be "on"

char* width[]={"Thin","Medium","Thick",NULL};//drop down menu names//
winio("Please Select a Thickness: %`7.3ls&",width,&wid);//drop down menu width 6, 3 selections//

winio("\n\n\t\t\t%bc[yellow]%^?bt[ Random ]@%bh&",Random,hlp,&help_switch);//button with help bubble
winio("\t%bc[red]%^bt[ Clear ]&",Clear);
winio("\t%bc[grey]%^bt[ Draw ]",Draw);

np=(float)n;//converts num into a float
{
do//while statement simply to find min and max values of x,y
{
p = (pow(1 - u, 3));//=(1-u)(1-u)(1-u),to the power of
g = (3 * (pow(1-u,2) * u));
s = (3 * pow((1-u)*u, 2));
t = pow(u, 3);

x0 = ((p*w1*x1) + (g*w2*x2) + (s*w3*x3) + (t*w4*x4)) / ((p*w1) + (g*w2) + (s*w3) + (t*w4));// starting x coordinate for the line
y0 = ((p*w1*y1) + (g*w2*y2) + (s*w3*y3) + (t*w4*y4)) / ((p*w1) + (g*w2) + (s*w3) + (t*w4));// starting y coordinate for the line
if (x0>xmax)
{xmax=x0;}
else
{xmax=xmax;}
if (x0<xmin)
{xmin=x0;}
else
{xmin=xmin;}
if (y0>ymax)
{ymax=y0;}
else
{ymax=ymax;}
if (y0<ymin)
{ymin=y0;}
else
{ymin=ymin;}
u=u+(1/(np-1));
c++;
}
while (c<np);//only continues when the number of times the formula has been pasted is equal to that of the number of points
x2max = xmax;//save new values as base values change
x2min = xmin;
y2max = ymax;
y2min = ymin;
y1 = y1-ymin+5;//minus' y min so y values start as close to y=0 as possible
y2 = y2-ymin+5;
y3 = y3-ymin+5;
y4 = y4-ymin+5;
x1 = x1-xmin+5;
x2 = x2-xmin+5;
x3 = x3-xmin+5;
x4 = x4-xmin+5;
u=0;//resets u value
c=0;
do
{
p = (pow(1 - u, 3));//=(1-u)(1-u)(1-u),to the power of
g = (3 * (pow(1 - u, 2) * u));
s = (3 * pow((1 - u) * u, 2));
t = pow(u, 3);

x0 = ((p * w1 * x1) + (g * w2 * x2) + (s * w3 * x3) + (t * w4 * x4)) / ((p * w1) + (g * w2) + (s * w3) + (t * w4));// starting x coordinate for the line
y0 = ((p * w1 * y1) + (g * w2 * y2) + (s * w3 * y3) + (t * w4 * y4)) / ((p * w1) + (g * w2) + (s * w3) + (t * w4));// starting y coordinate for the line

u=u+(1/(np-1));//calculates the value of u
x[c]=x0; y
CPP / C++ / C Code:
=y0;//given number on array,c, is equal to that of x01,y01
                                c++;//increment c so we get np points
                                }
                        while(c<np);        
                        winio("%bg%ca[Graphics Tablet]&",RGB(0,0,0));
                        winio("%bc[green]%^bt[ Return ]&",Refresh); 
                        winio("%bc[red]%^bt[ Close ]\n&",Close); 
                        winio("%`gr&",(x2max-x2min+5),(y2max-y2min+5),hand);//graphics tablet of size 400*300,reference name hand1
                        winio("%lw",&ctrl);//this must b present with the line above
                        select_graphics_object(hand);//makes sure the next lines refer to the tablet hand1
                        set_line_width(wid);
                        polyline(x,y,np,col);//displays a polygon of np points, colour=col, x,y taken from array 
                }   
                
        }                
                
}  

int Random()
{     
x1 = (rand() % 765) + 6;//creates a random number between 5-800
x2 = (rand() % 795) + 6;
x3 = (rand() % 795) + 6;
x4 = (rand() % 795) + 6; 
y1 = (rand() % 595) + 6;  
y2 = (rand() % 595) + 6; 
y3 = (rand() % 595) + 6; 
y4 = (rand() % 595) + 6;
w1 = (rand() % 5) + 1;
w2 = (rand() % 15) + 1;
w3 = (rand() % 17) + 1;
w4 = (rand() % 7) + 1;
n = (rand() % 92) + 8; 
help_switch=(help_switch+1)&0;//help message only displayed once
return 1;
}

int Clear()
{
x1=x2=x3=x4=1;
y1=y2=y3=y4=1;
w1=w2=w3=w4=1;
n=2;    
wid=2;
return 1;
}

int Draw()
{     
    if (b1==0)//to determine the colour selected by the user
    {
        if(b2==0)
        {
            if(b3==0)
            {
                col=80;
            }
            else
            {
                col=48;
            } 
        }       
        else
        {
            col=53;
        }    
    }
    else 
    {       
        col=40;
    }        
    return 0;//refreshes screen  
} 

int Close()
{
        return 0;
}

int Refresh()
{
        return 1;
}
  #2  
Old 27-Apr-2004, 14:54
warny_maelstrom warny_maelstrom is offline
Junior Member
 
Join Date: Jan 2004
Posts: 41
warny_maelstrom will become famous soon enough
Iv decided to gut my program and start pretty much from stratch which should make it easier. But now im getting the error "floating point subscript is not permitted" on lines 37,38 and I have no idea what that means or how to fix it. Im open to any answers, suggestions...
[c]
#pragma windows 300000,500000,"cwp_ico.rc" //means dosbox is not displayed
#include<stdio.h>
#include<math.h>
#include<windows.h>
#include<dbos\graphics.h>
#include<stdlib.h>

double u=0, g, p, s, t, np=99;
double y0, x0, b4=0, b3=0, b2=0, b1=1, x1=1, x2=1, x3=1, x4=100, y1=1, y2=1, y3=1, y4=100, w1=1, w2=1, w3=1, w4=1,
c=0, n=2, col=0, wid=2;
short int x[100],y[100];//array with a maximum of 100 values
int main()
{
winio("%bg%ca[Data Input Screen]&",RGB(100,255,100));
winio("%fn[Arial]%tsEnter in 4 values for the x coordinates: \t%rd\t%rd\t%rd\t%rd\n&",1.2, &x1, &x2, &x3, &x4);
winio("Enter in 4 values for the y coordinates: \t%rd\t%rd\t%rd\t%rd\n&",&y1, &y2, &y3, &y4);
winio("Enter in 4 values for the weighting: \t%rd\t%rd\t%rd\t%rd\n&",&w1, &w2, &w3, &w4);
winio("\n\n%gr[grey]&",600,400);
polyline(x,y,np,col);//displays a polygon of np points, colour=col, x,y taken from array
winio("\n\n%bc[green]%^bt[ Draw ]\n&");
winio("\n\n%bc[gray]%^bt[ Close ]");
}

int Draw()
{
c=0;
do
{
p = (pow(1 - u, 3));//=(1-u)(1-u)(1-u),to the power of
g = (3 * (pow(1 - u, 2) * u));
s = (3 * pow((1 - u) * u, 2));
t = pow(u, 3);

x0 = ((p * w1 * x1) + (g * w2 * x2) + (s * w3 * x3) + (t * w4 * x4)) / ((p * w1) + (g * w2) +
(s * w3) + (t * w4));// starting x coordinate for the line
y0 = ((p * w1 * y1) + (g * w2 * y2) + (s * w3 * y3) + (t * w4 * y4)) / ((p * w1) + (g * w2) +
(s * w3) + (t * w4));// starting y coordinate for the line

u=u+(1/(np-1));//calculates the value of u
/*line 37*/ x[c]=x0;//given number on array,c, is equal to that of x0,y0
y
CPP / C++ / C Code:
=y0;
                c++;//increment c so we get np points
                }
         while(c<np);                             
return 1;//refreshes the screen                    
} 

int Close()
{
        return 0;//closes program
}
  #3  
Old 28-Apr-2004, 07:32
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Hi warny.

I think that you are trying to shove a double into a short.

You define x[] as a short and y[] as a short here:
CPP / C++ / C Code:
double u=0, g, p, s, t, np=99;
double y0, x0, b4=0, b3=0, b2=0, b1=1, x1=1, x2=1, x3=1, x4=100, y1=1, y2=1, y3=1, y4=100, w1=1, w2=1, w3=1, w4=1, 
c=0, n=2, col=0, wid=2; 
short int x[100],y[100];//array with a maximum of 100 values   


And then you are trying to place a double into it here.
[c]
/*line 37*/ x[c]=x0;//given number on array,c, is equal to that of x0,y0
y
CPP / C++ / C Code:
=y0;

  #4  
Old 28-Apr-2004, 10:54
warny_maelstrom warny_maelstrom is offline
Junior Member
 
Join Date: Jan 2004
Posts: 41
warny_maelstrom will become famous soon enough
Quote:
Originally Posted by dsmith
Hi warny.

I think that you are trying to shove a double into a short.

You define x[] as a short and y[] as a short... then you are trying to place a double into it here.
[c]
/*line 37*/ x[c]=x0;//given number on array,c, is equal to that of x0,y0
y
CPP / C++ / C Code:
=y0;

Indeed i am but I cant seem to find anyway round it, Iv tried changing the x0 value so that it is now a short int or an int and it still gives me the exact same error, "floating point subscript is not permitted", even though x0/y0 are now ints. So I really dont understand why it doesnt work.
[c]
x[c]=(int)x0;
y
CPP / C++ / C Code:
=(int)y0;

I was also wondering if anyone knows how to use:
CPP / C++ / C Code:
destroy_window()
Because it would be a way round the above, the job of "destroy_window" if you hadnt realised was to close all the open windows.
Last edited by warny_maelstrom : 28-Apr-2004 at 11:41.
  #5  
Old 28-Apr-2004, 22:54
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,243
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by warny_maelstrom
Indeed i am but I cant seem to find anyway round it, Iv tried changing the x0 value so that it is now a short int or an int and it still gives me the exact same error, "floating point subscript is not permitted", even though x0/y0 are now ints. So I really dont understand why it doesnt work.
[c]
x[c]=(int)x0;
y
CPP / C++ / C Code:
=(int)y0;
"floating point subscript" means the subscript is a floating point value (double) and that is not allowed. IOW, you've defined c as a double and it must be an integer value.
__________________

Age is unimportant -- except in cheese
 
 

Recent GIDBlogToyota - 2008 August Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 20:02.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.