Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,149 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,065 people online right now. Registration is fast and FREE... Join Now!




says illegal else w/o matching if and error about argument list

2 Pages V  1 2 >  
Reply to this topicStart new topic

says illegal else w/o matching if and error about argument list, may be my compiler?

skp1985
2 Jun, 2007 - 12:11 PM
Post #1

New D.I.C Head
*

Joined: 23 Apr, 2007
Posts: 19


My Contributions
Hi my compile is displaying the errors below. I do not know why. Does anyone think it's my compiler b/c it gives me tons of problems. Can anyone give any suggestions or hints? Thanks.
error C2064: term does not evaluate to a function taking 1 arguments
for this part
CODE

void process (student &temp)
{
float quiz, avg, tot_avg;
char grade;
    temp.avg = tot_avg(  tot_avg);
    temp.grade= test_grade ( tot_avg, grade);
}


and total_avg comes from
CODE

float tot_avg( float tot_avg)
{
    float quiz, avg;
    tot_avg=(quiz*.10)+ avg/2;
    return (tot_avg);
}


error C2181: illegal else without matching if
is for this section
CODE

int read_data( student list[], int limit)
{
    ifstream fin;
    string dataf_in, name, f_name, l_name;
    int i=0;
    cout<<"Enter input file name:";
    getline (cin,dataf_in);
    fin.open(dataf_in.c_str());
    if (!fin.fail());
    {
        get_info (list[i], fin, name, f_name, l_name);
        while (fin && i < limit)
        {
            i++;
            if (i<limit)
                get_info (list[i], fin, name, f_name, l_name);
        }
    }
    else
        cout<<"Bad file name"<<endl;
    return (i);
}


User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Says Illegal Else W/o Matching If And Error About Argument List
2 Jun, 2007 - 01:40 PM
Post #2

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,442



Thanked: 66 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
CODE


    if (!fin.fail());
    {
        get_info (list[i], fin, name, f_name, l_name);
        while (fin && i < limit)
        {
            i++;
            if (i<limit)
                get_info (list[i], fin, name, f_name, l_name);
        }
    }
    else
        cout<<"Bad file name"<<endl;


I would think you can't have the semi-colon at the end of your if. That's ending the if, & the else has no if.
User is online!Profile CardPM
+Quote Post

NickDMax
RE: Says Illegal Else W/o Matching If And Error About Argument List
2 Jun, 2007 - 08:20 PM
Post #3

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,858



Thanked: 49 times
Dream Kudos: 550
My Contributions
Well I am shooting from the hip here... but I count at least 3 different uses for the identifier "tot_avg" -- You declare it a float variable in the process() function. It is a function, AND another float value in the function of the same name tot_avg(). You know there ARE other variable/function name out there.

Try changing the name of the function tot_avg to something flashy like "Calculate_Total_Average" and I bet it would solve that problem. -- Since the identifier tot_avg inside process() is within the scope of that function and therefore a float variable -- not a function taking 1 argument.

No2Pencil has the other.

Note... if you get errors chances are its you, not the compiler. Granted I don't think in the first case your compiler gave you very much information. I would have expected such an error to be even more cryptic saying something about conversion of data type float to float (*)(float). So another compiler might give you more or less descriptive error information... Heck it might even find errors in a totally different order. But always take a careful look at your code.

Believe me I have cursed compiler writers and their mothers... but in the end it has always been my fault. -- so far.

User is offlineProfile CardPM
+Quote Post

Topher84
RE: Says Illegal Else W/o Matching If And Error About Argument List
4 Jun, 2007 - 09:45 AM
Post #4

D.I.C Head
Group Icon

Joined: 4 Jun, 2007
Posts: 232


Dream Kudos: 25
My Contributions
1. Take the semicolon out of your initial if satement
2. You can take that else out completely since you are only checking one thing. Which should solve your illegal matching situation.

and with your function problems.. like the other guy suggested, rename your variables/functions to something more meaningful and give it a go.. try not to give variables and functions the exact same name smile.gif

Suggestion: An even better thing to do is when you try to open the file initially make a while statement that says "while the file name is bad prompt the user for the info again". This will save you from even doing an else/if statement since if you get out of that while statement you know you have a valid file.

This post has been edited by Topher84: 4 Jun, 2007 - 09:49 AM
User is offlineProfile CardPM
+Quote Post

skp1985
RE: Says Illegal Else W/o Matching If And Error About Argument List
5 Jun, 2007 - 10:40 AM
Post #5

New D.I.C Head
*

Joined: 23 Apr, 2007
Posts: 19


My Contributions
thanks a bunch. it's amazing how i can sit here for hours and not even notice these mistakes. its so frustrating, you're all geniuses, i dont know how you do it hopefully one day i will !! thanks again.
User is offlineProfile CardPM
+Quote Post

Topher84
RE: Says Illegal Else W/o Matching If And Error About Argument List
5 Jun, 2007 - 10:42 AM
Post #6

D.I.C Head
Group Icon

Joined: 4 Jun, 2007
Posts: 232


Dream Kudos: 25
My Contributions
QUOTE(skp1985 @ 5 Jun, 2007 - 11:40 AM) *

thanks a bunch. it's amazing how i can sit here for hours and not even notice these mistakes. its so frustrating, you're all geniuses, i dont know how you do it hopefully one day i will !! thanks again.



np you gotta start somewhere ph34r.gif if you are programming in visual studios you should get to be really good buddies w/ the debugger which normally will solve 99% of little problems
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: Says Illegal Else W/o Matching If And Error About Argument List
5 Jun, 2007 - 11:31 AM
Post #7

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,858



Thanked: 49 times
Dream Kudos: 550
My Contributions
QUOTE(Topher84 @ 5 Jun, 2007 - 11:42 AM) *

QUOTE(skp1985 @ 5 Jun, 2007 - 11:40 AM) *

thanks a bunch. it's amazing how i can sit here for hours and not even notice these mistakes. its so frustrating, you're all geniuses, i dont know how you do it hopefully one day i will !! thanks again.



np you gotta start somewhere ph34r.gif if you are programming in visual studios you should get to be really good buddies w/ the debugger which normally will solve 99% of little problems


It is often easier to troubleshoot someone else code rather than your own. The reason it that you mind understands the logic behind what you did -- you know what you mean, but the compiler doesn't. The same kind of thing often happens in written language. I have read back over papers I turned in at school and found myself wondering how I ever passed a class.

When you are really stuck on a problem there are a few things you can do. #1 Try the debugger -- often this will help you see what it happening. #2 Print it out. -- I don't know why, but at least for me, I think better on paper. You can make notes, you can doodle, you can draw flow charts, all little things that help you see your code from different angles. #3 Sleep on it. Take a walk, get a sandwich, take your wife (or husband, women program too) to dinner and beyond, get your mind away from the problem. -- Just the other day there was a post here that I just could not solve, I even went so far as to tell the poster that they would have to seek higher wisdom. I went to bed, and woke up with the answer. #4 Rewrite the offending code from scratch. I don't know why, but sometimes my brain just needs a reboot. Often in the trouble shooting process I have learned more about what I am trying to accomplish and the rewrite works better anyway. (again the same can often be said for written language).
User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Says Illegal Else W/o Matching If And Error About Argument List
5 Jun, 2007 - 11:44 AM
Post #8

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,442



Thanked: 66 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
QUOTE(NickDMax @ 5 Jun, 2007 - 12:31 PM) *

When you are really stuck on a problem there are a few things you can do. #1 Try the debugger -- often this will help you see what it happening. #2 Print it out. -- I don't know why, but at least for me, I think better on paper. You can make notes, you can doodle, you can draw flow charts, all little things that help you see your code from different angles. #3 Sleep on it. Take a walk, get a sandwich, take your wife (or husband, women program too) to dinner and beyond, get your mind away from the problem. -- Just the other day there was a post here that I just could not solve, I even went so far as to tell the poster that they would have to seek higher wisdom. I went to bed, and woke up with the answer. #4 Rewrite the offending code from scratch. I don't know why, but sometimes my brain just needs a reboot. Often in the trouble shooting process I have learned more about what I am trying to accomplish and the rewrite works better anyway. (again the same can often be said for written language).

These are all great tips. The only one I would add is, explain it to someone that doesn't know anything about programming. Spelling it all out in plain English causes you to go through the process in great detail. I usually find a simple error by 'beach-combing' in this manor. In fact, I often times find myself stopping mid sentence & running off to the computer.
User is online!Profile CardPM
+Quote Post

NickDMax
RE: Says Illegal Else W/o Matching If And Error About Argument List
5 Jun, 2007 - 01:12 PM
Post #9

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,858



Thanked: 49 times
Dream Kudos: 550
My Contributions
QUOTE
explain it to someone that doesn't know anything about programming.
Here here! This is a good step. Though it does not have to be someone who knows nothing of programming... just spell it out in plain language (doesn't have to be english smile.gif)
User is offlineProfile CardPM
+Quote Post

Topher84
RE: Says Illegal Else W/o Matching If And Error About Argument List
6 Jun, 2007 - 04:55 AM
Post #10

D.I.C Head
Group Icon

Joined: 4 Jun, 2007
Posts: 232


Dream Kudos: 25
My Contributions
ah yes... I have one too smile.gif

1. Don't try to do it all in one giant step.. take baby steps.. as in work on one function at a time until it is correct before you move on! i can't count how many times i've tried to write a complete program in one go only to have created way more problems than I needed!
User is offlineProfile CardPM
+Quote Post

skp1985
RE: Says Illegal Else W/o Matching If And Error About Argument List
6 Jun, 2007 - 11:42 AM
Post #11

New D.I.C Head
*

Joined: 23 Apr, 2007
Posts: 19


My Contributions
great tips, its hard to get help b/c no one has a clue what im talking about in the real world. the tips all make so much sense. i like the ones about printing it and doing one function at a time. o and yessssss women do program too smile.gif though at times i feel like im the only one. LOL

User is offlineProfile CardPM
+Quote Post

jasonprince2
RE: Says Illegal Else W/o Matching If And Error About Argument List
7 Jun, 2007 - 03:49 PM
Post #12

New D.I.C Head
*

Joined: 6 Jun, 2007
Posts: 19


My Contributions
I think I know about the illegal if statement.
Try this as your code. usually you need to have braces with if statements.

CODE

          if (i<limit)
{                
get_info (list[i], fin, name, f_name, l_name);
}    
    }
    }
    else
{  
      cout<<"Bad file name"<<endl;
}



This post has been edited by jasonprince2: 7 Jun, 2007 - 03:50 PM
User is offlineProfile CardPM
+Quote Post

2 Pages V  1 2 >
Reply to this topicStart new topic
Time is now: 12/1/08 10:59PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month