Thread: Need some moderate!

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    18

    Unhappy Need some moderate!

    hi,GUYS!
    i have a problem with this c++ coding........
    why i have an error when i compile it?
    and why it didn't give me the correct output?
    as such PISAS=ISAS/100*30
    if let say, ISAS is 50/100*30..... it should store the output of 15 in the PISAS Variable. why it didn't? plsssss help...urgent!!!


    here is the code!!!




    #include<iostream.h>
    void main()

    {
    Char cReply;
    Char Studentname;
    int MT1; int PMT1;
    int ISAS; int PISAS;
    int MT2; int PMT2;
    int PROJECT; int PPROJECT;
    int 100=100; int 30=30;
    do
    {
    cout<<"Enter Student Name";
    cin>>Studentname;
    cout<<"Enter MT1 Marks";
    cin>>MT1;
    cout<<"Enter ISAS Marks";
    cin>>ISAS;
    cout<<"Enter MT2 Marks";
    cin>>MT2;
    cout<<"Enter PROJECT Marks";
    cin>>PROJECT;
    PMT1=MT1/100*30;
    cout<<"The Percentage of MT1 is"<<PMT1<<endl;
    PISAS=ISAS/100*30;
    cout<<"The Percentage of ISAS is"<<PISAS<<endl;
    PMT2=MT2/100*30;
    cout<<"The Percentage of MT2 is"<<PMT2<<endl;
    PPROJECT=PROJECT/100*30;
    cout<<"The Percentage of Project is"<<PPROJECT<<endl;
    cout<<"Do you want to input another Student(y/n)";
    cin>>cReply;
    }while(cReply! > 'n' && cReply != 'N' );
    }

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    >int 100=100; int 30=30;

    Invalid variable names.

    >Char cReply;

    As far as I know, Char is not a standard C++ type.

    >PMT1=MT1/100*30;

    Using division on integer-variables is riskfull because of round-off errors.

    BTW, how can you get compile-errors and run your program? Which compiler do you use?

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    18

    like this!!

    i am using Microsoft visual studio C++. i thought this is a very easy program but why i got the error? Can anyone here help me with this program? just correct it for me....... i just wanna to see the output of it.
    is there anything i could do? change the Int to float. is it?
    In Need this code!!! help

  4. #4
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    Your way of calculating percentages is wrong. If T is the total of marks and N is a number of marks, then the percentage is

    P = N / T * 100

    Note that you can't assign a string to a char, you should use type string for that. This worked for me, I use C++Builder.

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        char cReply;
        string Studentname;
        int MT1, PMT1, ISAS, PISAS, MT2, PMT2, PROJECT, PPROJECT;
        int TotalMarks;
    
        do
        {
            cout << "Enter Student Name ";
            cin >> Studentname;
            cout << "Enter MT1 Marks ";
            cin >> MT1;
            cout << "Enter ISAS Marks ";
            cin >> ISAS;
            cout << "Enter MT2 Marks ";
            cin >> MT2;
            cout << "Enter PROJECT Marks ";
            cin >> PROJECT;
            
            TotalMarks = MT1 + ISAS + MT2 + PROJECT;
            
            PMT1 = float (MT1) / float (TotalMarks) * 100;
            cout << "The Percentage of MT1 is " << PMT1 << endl;
            PISAS = float (ISAS) / float (TotalMarks) * 100;
            cout << "The Percentage of ISAS is "<< PISAS << endl;
            PMT2 = float (MT2) / float (TotalMarks) * 100;
            cout << "The Percentage of MT2 is "<< PMT2 << endl;
            PPROJECT = float (PROJECT) / float (TotalMarks) * 100;
            cout << "The Percentage of Project is " << PPROJECT << endl;
            cout << "Do you want to input another Student(y/n) ";
            cin >> cReply;
        }
        while (cReply != 'n' && cReply != 'N');
        
        return 0;
    }

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    18

    HELP!

    are they anyone who can help me solving this programming problem for me? i am looking forward it...... thanks !

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    362
    Mitchell,

    I'm in agreement with Shiro. Your code, as supplied, didn't even compile (and I don't even have to test it).

    Char is not a valid data type unless you use #typedef. You didn't.

    int 100=100; and int 30=30; are invalid because neither starts with a letter or the underscore character. Not that either makes a modicum of sense anyway.

    You use 'void main()' vice 'int main()' which indicates that you've not read the FAQ, a single book dealing with this language or any of the untold number of threads that have been posted concerning this mistake.

    By many conventions, variable names beginning with uppercase letters refer to "classes" and names written entirely in uppercase letters refer to "constants", not modifiables. Note that I say, "By many conventions,...". This isn't written in stone, but consistency in your program is very important.

    if let say, ISAS is 50/100*30..... it should store the output of 15 in the PISAS Variable. why it didn't?
    Ten minutes of researching 'integer math' would have enlightened you as to why this doesn't give you the output you "expected", though I refer you back to the beginning of my response.

    is there anything i could do?
    Yes, there certainly was. If this thread isn't a joke, there still is. Search for any posting by Prelude, click on the link in his "signature" regarding the asking of "smart" questions and read it, preferably more than once.
    "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Just when you thought Bush couldn't surprise you...
    By Salem in forum A Brief History of Cprogramming.com
    Replies: 132
    Last Post: 07-20-2007, 05:15 PM
  2. the history of Wingdings (and other nonsensical things)
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 01-19-2002, 01:51 PM