Function, but mine is if else...

This is a discussion on Function, but mine is if else... within the C++ Programming forums, part of the General Programming Boards category; So, there is my coding, but i use, loop, and if else, BUT the one suppose is Function... Code: #include<iostream.h> ...

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    12

    Function, but mine is if else...

    So, there is my coding, but i use, loop, and if else, BUT the one suppose is Function...

    Code:
    #include<iostream.h>
    #include<string.h>
    int main()
    {
        char lect_name[30],subject[30];
        char grade,status;
        int mark;
        int numbof_student;
        float sum=0;
        float average;
        
        cout<<"Enter Your Lecturer name : ";
        cin>>lect_name;
        
        cout<<"Enter Your Subject code : ";
        cin>>subject;
        
        cout<<"Enter Number Of Student : ";
        cin>>numbof_student;
        
        for(int s=0; s<numbof_student; s++)
        {
            cout<<s+1<<" student enter grade:";
            cin>>grade;
            
            if(grade=='A')
            {
            mark=4;
            }
            
            else if(grade=='B')
            {
            mark=3;
            }
            
            else if(grade=='C')
            {
            mark=2;
            }
            
            else if(grade=='D')
            {
            mark=1;
            }
            
            else 
            {
                cout<<"Wrong Input"<<endl;
            }
            sum=sum+mark;
    
        average=sum/numbof_student;
        
        if ((average>=3.5) &&(average<=4.0))
        {
        cout<<"Excellence";
        }
    
        else if ((average<=3.0) &&(average<=3.5))
        {
        cout<<"Good";
        }
    
        else if ((average<=2.0) &&(average<=3.0))
        {
        cout<<"Average";
        }
    
        else if (average<=2.0)
        {
        cout<<"Poor";
        }
        }
    
        cout<<"\n\n\t\tUniversiti Pendidikan Sultan Idris";
        cout<<"\n\n\t\tTeaching & Learning Evaluation Report";
        cout<<"\n\nName : "<<lect_name<<endl;
        cout<<"Subject Code : "<<subject<<endl;
        cout<<"Average :"<<average<<endl;
        cout<<"Status : "<<status<<endl;
    }
    i did coding for function, but blablabla... still error and error and then hard i try the simplest coding...

    can sumone?

    currently im still working to covert it to function...

  2. #2
    Registered User
    Join Date
    Nov 2011
    Posts
    67
    Have you thought about using the switch case function? That would probably be alot more effecient, and use up alot less space =)

  3. #3
    Registered User
    Join Date
    Dec 2011
    Posts
    12
    Currently im working to convert it to function coding...

    and yes, i try to use, switch, but the typical problem is FUNCTION...

    working...

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,301
    This will probably help: C Function tutorial
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  5. #5
    Registered User
    Join Date
    Dec 2011
    Posts
    12
    i had submit,

    yes, not above there, i did my function coding...

    i had done my assignment with non-stop working...

    without any help!

  6. #6
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,425
    i had done my assignment with non-stop working...
    welcome to the world of programming.....

    well done...! :->
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  7. #7
    Registered User
    Join Date
    Dec 2011
    Posts
    12
    tq for ur help even not much.. TQ~

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,543
    Recommend switch char to std::string.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. a bug of gcc, or a bug of mine?
    By xinwu in forum C Programming
    Replies: 4
    Last Post: 11-29-2011, 06:30 PM
  2. a C++ library of mine.
    By jinhao in forum A Brief History of Cprogramming.com
    Replies: 72
    Last Post: 09-13-2008, 02:19 PM
  3. Using other programs in mine
    By mramazing in forum C++ Programming
    Replies: 12
    Last Post: 07-02-2006, 02:19 AM
  4. Function of mine isn't taking strings right.
    By suzakugaiden in forum C++ Programming
    Replies: 15
    Last Post: 01-30-2006, 06:02 PM
  5. Another game of mine...
    By valar_king in forum Game Programming
    Replies: 7
    Last Post: 01-03-2002, 08:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21