p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   All Other Wrox Books (http://p2p.wrox.com/forumdisplay.php?f=116)
-   -   Bug or no to bug learning C using VS.Net to compil (http://p2p.wrox.com/showthread.php?t=54067)

tesh February 14th, 2007 01:06 PM

Bug or no to bug learning C using VS.Net to compil
 
Gurus.

I have written the following code with the help of Ivor Horton's Beginning C :

// Structures, Arrays of Structures.

#include "stdafx.h"
#include "stdio.h"
#define MY_ARRAY 15
#define BASIS 360

    struct swap
    {
        char counterParty[10];
        float notional;
        float intRate;
        int busDays;
        //int basis = 360;
        float flows;
    };

void main()
{

    /*Arrays of Structures*/

    swap myArraySwap[MY_ARRAY];


    int hcount = 0;
    int i = 0;
     //='\0';

// for (hcount = 0; hcount < 5 ; hcount++ )
    do
    {
        char test = NULL;
        printf("\nWould you like to enter Swaps (Y or N)?:");

        test = getchar();

        if (test != 'Y') //|| test !='y')
            break;

        printf("\nEnter CounterParty:");
        scanf("%s", &myArraySwap[hcount].counterParty );
        printf("\nEnter Notional :" );
        scanf("%f", &myArraySwap[hcount].notional );
        printf("\nEnter Interest Rate:" );
        scanf("%f", &myArraySwap[hcount].intRate );
        printf("\nEnter Number of days:" );
        scanf("%d", &myArraySwap[hcount].busDays );
        myArraySwap[hcount].flows = (myArraySwap[hcount].notional * (myArraySwap[hcount].intRate/100.0f) * ((float)myArraySwap[hcount].busDays/360.0f));

        hcount++;
    }
    while (hcount < 5);

    for (i=0 ; i < hcount ; i++)
    {
    printf("\nCounter Party: %s",myArraySwap[hcount].counterParty);
    printf("\nFlows %f", myArraySwap[i].flows);
    printf("\nDone");
    }


}


Problem:

First time around the var test = '' and I can enter a value i.e. Y

here is the dos output:

Would you like to enter Swaps (Y or N)?:Y

Enter CounterParty:Test

Enter Notional :1000

Enter Interest Rate:5.25

Enter Number of days:35

Would you like to enter Swaps (Y or N)?:

second time around the at the point of test = getchar(); test is set to '0 ' automatically and I am not able to enter Y or N.

when the app reaches:test = getchar(); it automatically sets the var from Y 89 to : 0 ''

is this compiler related i have vs.net 2003 ?

i have also tried scanf and get the same :(

thank you.

tesh
[8D]


All times are GMT -4. The time now is 04:34 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.