LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Need Quick Help With C Problem!!! (https://www.linuxquestions.org/questions/programming-9/need-quick-help-with-c-problem-244982/)

']['HeBroken 10-20-2004 03:28 AM

Need Quick Help With C Problem!!!
 
ok i have class in about 4 hours and im stessing the hell out cause this program is so easy to write but yet so hard for me. im only one week into programming and i have variables, constants, main fuction, if's elses and what not coming out of my ear. well here is the problem im using Visual Studio 2005 beta version and i wrote the program in it and i have a few errors ill show you what i mean....

Code:

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int main(void)
{
        float fPrice, fResult;
        char cCode, cOper;
       
                printf("\n Please Enter The Price Of The Item");
                        scanf ("%f", &fPrice);
                        fflush(stdin);


                printf("\n Please Enter the Discount Code");
                        scanf ("%c", &cCode);
                        fflush(stdin);

        switch( tolower (cCode) )
        {
        case 'h':
        case 'H':
       
        fResult = .5 * fPrice;
        cOper = '*';
        break;
       
        case 'f':
       
        fResult = .4 * fPrice;
        cOper = '*';
        break;

        case 't':
       
        fResult = .33 * fPrice;
        cOper = '*';
        break;

        case 'q':
        case 'Q':

        fResult = .25 * fPrice;
        cOper = '*';
        break;

        case 'z':

        if ( cCode == 'z')
        {
        fResult = fPrice;
        }
        else
{
        printf("\n You Gotta Pay Full Price Biatch");
        return 1;
}
        printf("%f %f %c", fResult, fPrice, cCode);

        return 0;
        }


then i get the errors messages

Code:

------ Build started: Project: f, Configuration: Debug Win32 ------
Compiling...
fff.c
c:\Documents and Settings\Administrator\Desktop\f\fff.c(11) : warning C4996: 'scanf' was declared deprecated
        c:\Program Files\Microsoft Visual Studio 8\VC\include\stdio.h(276) : see declaration of 'scanf'
c:\Documents and Settings\Administrator\Desktop\f\fff.c(16) : warning C4996: 'scanf' was declared deprecated
        c:\Program Files\Microsoft Visual Studio 8\VC\include\stdio.h(276) : see declaration of 'scanf'
c:\Documents and Settings\Administrator\Desktop\f\fff.c(24) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
c:\Documents and Settings\Administrator\Desktop\f\fff.c(30) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
c:\Documents and Settings\Administrator\Desktop\f\fff.c(36) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
c:\Documents and Settings\Administrator\Desktop\f\fff.c(43) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
c:\Documents and Settings\Administrator\Desktop\f\fff.c(63) : fatal error C1075: end of file found before the left brace '{' at 'c:\Documents and Settings\Administrator\Desktop\f\fff.c(6)' was matched
Build log was saved at "file://c:\Documents and Settings\Administrator\Desktop\f\Debug\BuildLog.htm"
f - 1 error(s), 6 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



now i need some serious help im so mind screwed i kant think... please help me....... thanx in advance...

barisdemiray 10-20-2004 04:00 AM

- You can declare fPrice and fResult as double to prevent possible data loss
- You didn't close the brace of `switch' as i see.
and I would ignore the message about scanf..

Also, try not to use a windows box with the administrator account. It's almost same with using root account in GNU/Linux.


All times are GMT -5. The time now is 08:59 AM.