1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

floating point (invalid)

Discussion in 'C++' started by fikri, Oct 3, 2010.

  1. fikri

    fikri New Member

    Joined:
    Oct 3, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    hey guys, i need help with this question.

    i need to write a program to get the output which is :

    i) there will be two class which is info_student and mark_student. class mark_student will be friend to a class info_student.

    ii) class info student will have name and ic with data type character as a variable. it also have function set_data that accept two variable above as a pointer in the parameter list.

    iii) while mark_student will have mark1, mark2 and total with data type float. the function is setmark, calculateMark and display.

    i already programmed and compiled the code, but i have the output show "floating point invalid" when i input the data. what have i done wrong here? :(


    Code:
    #include<iostream.h>
    class info_mark;
    class info_student
    {
    private:
    char name,ic;
    public:
    int student()
    {return name,ic;}
    };
    
    class info_mark
    {
    float mark1,mark2;
    public:
    int calculate_mark()
    {return mark1 +mark2;}
    };
    
    void main()
    {
    char a,b;
    float m,n;
    cout<<"Name:";
    cin>>a;
    cout<<"Ic:";
    cin>>b;
    
    cout<<"mark 1:";
    cin>>m;
    cout<<"mark 2:";
    cin>>n;
    
    cout<<"total:"<<m+n;
    }
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Isn't the point of the assignment that main uses the classes? It doesn't.

    What line does the error occur on? What data did you input?

    char is a single character, not a character string. You can only store individual characters such as 'a' and 'Z' in these variables. You cannot store a name like "fikri" - that would require a character array of at least 6 chars. Maybe the problem is that you entered multiple characters for the name.
     
  3. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
    try

    Code:
    #include [COLOR=Red]<iostream>[/COLOR] 
    [COLOR=Red]#include <string>[/COLOR]
    .......
    [COLOR=Red]int[/COLOR] main() { 
    [COLOR=Red]string[/COLOR] a,b;
    ........
    
    
     

Share This Page