Welcome to Dream.In.Code
Become a C++ Expert!

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




C++ homework error problem

 
Reply to this topicStart new topic

C++ homework error problem, coding errors for arrays...

asiandoll
17 Mar, 2008 - 10:51 AM
Post #1

New D.I.C Head
*

Joined: 17 Mar, 2008
Posts: 7

Hi everyone,

I have been working on my project for sometime now and I have been stuck on it for a while. I created an array for the user to chose between two things, ie if a user input 1 should be able to go to the grade calculator or if the user input 2 then it should go to the Calculator. I have one error on my code but I don't know where I went wrong. Can someone help me please... I would really appreciate any help as soon as possible for it is due on Thursday. Thank you in advance...

CODE


#include<iostream>
    #include<iomanip>


    using std::cout;
    using std::cin;
    using std::endl;
    using std::setprecision;
    using std::ios;
    using std::setiosflags;

void displaygrader();
void displaycalculator();
    

int main()


    {
        int choice;
        int  left, right;
        int Enter1;
        int Enter2;
        char oper;          
        int  result;        
        char name[50];
        char Class[100];
        char Section[100];            
        int    average,
            a,
            b,
            c,
            d,
            f,
            n,
            sum,
            gpa,
            grade,                    
            gradeCounter,
            total;
            
            
        
        //initialization phase
        n=1;
        grade=0;
        gradeCounter=n;
        total=0;
        a=4;
        b=3;
        c=2;
        d=1;
        f=0;                        //prepare to loop
        
        
        
          //display output in fixed-point notation
    //with two decimal places
        cout <<setiosflags (ios::fixed) <<setprecision(2);
        
        
        // processing phase
        cout<<"Welcome to my program"<<endl;
        cout<<endl;
        cout<<endl;
        cout<<"What is your name? I would prefer it, if you entered only your first name"<<endl;
        cin>>name;
        cout<<"So tell me "<<name<< "Which program would like to use the Grader or the Calculator"<<endl;
        cout<<endl;
        do
        {
        cout<<"1      Display grader"<<endl;
        cout<<"2      Display calculator"<< endl;
        cout<<"3      End program" <<endl;
        cout<<"Enter your choice: ";
        cin>> choice;
        if (choice == 1)
            displaygrader();
            else if(choice == 2)
                displaycalculator();    
        cout<<"What class are you in"<<endl;
        cin>>Class;
        cout<<"What section are you in then "<<name<<endl;
        cin>>Section;
        cout<<endl;
        cout<<endl;
        cout<<"Okay enough of information. It's time to calculate your grades"<<endl;
        cout<<endl;
        cout<<endl;
        cout<<"Please enter the number of grades to be calculated:    "<<endl;
        cin>>n;
        }
    
        //loop statment
        while (gradeCounter <= n); {    
            cout<<"Please enter grade: ";    
            cin>>grade;                        
            
            total=total + grade;            
            gradeCounter= gradeCounter + 1;    
            }//end while



        
        
            
            //Calculation of the problem
            average=total/n;
            sum=total+grade;
            cout<<"Your average is "<<average<<"%"<<endl;
            cout<<"The sum of your scores is "<<sum<<endl;
            cout<<endl;
            cout<<endl;

            
            
            
            

                if (average>=84) {
                    cout<<"You received an A in the course! good job!"<<endl;
                    cout<<endl;
                    cout<<"Keep up the good work!"<<endl;
                    
                }
                    else if(average>=66) {
                    cout<<"You receieved a B in the course! keep up the good work!"<<endl;
                    cout<<endl;
                    cout<<endl;
                        
                    }
                        else if (average>=50) {
                        cout<<"You received a C in the course. You need improvement!"<<endl;
                        cout<<endl;
                        cout<<"You can do better!"<<endl;
                            
                        }
                            else if (average>=45) {
                            cout<<"You received a D! that is terrible!"<<endl;
                            cout<<endl;
                            
                                
                            }
                                else if (average<=44 && average >=0) {
                                cout<<"You received an F! Im sorry but you have to take the course again!"<<endl;
                                cout<<endl;
                                    
                    }
                            // GPA Statment
                            gpa=average/n;
                            if (average>=84)
                                cout<<"You gpa is: 4.0"<<endl;
                            else if (average>=66)
                                cout<<"Your gpa is: 3.75"<<endl;
                            else if (average>=50)
                                cout<<"Your gpa is: 2.00"<<endl;
                            else if (average>=45)
                                cout<<"Your gpa is: 1.00"<<endl;
                                else
                   cout<<"You failed study harder and push your gpa up!"<<endl;
                            cout<<endl;
                            cout<<endl;
                            cout<<endl;

                            
  
    
    while (cin >> left >> oper >> right) {
        switch (oper) {
            case '+': result = left + right;
                      break;
            case '-': result = left - right;
                      break;
            case '*': result = left * right;
                      break;
            case '/': result = left / right;
                      break;
            default : cout << "Bad operator '" << oper << "'" << endl;
                      
                cout << result << endl << endl;
        }

        return 0;
    }


User is offlineProfile CardPM
+Quote Post

Amadeus
RE: C++ Homework Error Problem
17 Mar, 2008 - 10:53 AM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,228



Thanked: 40 times
Dream Kudos: 25
My Contributions
Can you please post the error you are receiving?
User is offlineProfile CardPM
+Quote Post

asiandoll
RE: C++ Homework Error Problem
17 Mar, 2008 - 10:56 AM
Post #3

New D.I.C Head
*

Joined: 17 Mar, 2008
Posts: 7

QUOTE(Amadeus @ 17 Mar, 2008 - 11:53 AM) *

Can you please post the error you are receiving?


error is: end of file found before the left brace '{'
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: C++ Homework Error Problem
17 Mar, 2008 - 11:13 AM
Post #4

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,228



Thanked: 40 times
Dream Kudos: 25
My Contributions
You appear to have one more opening brace that you do closing braces. I'd go though the code tracking the sets of {}, and see where the missing one is.
User is offlineProfile CardPM
+Quote Post

asiandoll
RE: C++ Homework Error Problem
17 Mar, 2008 - 11:25 AM
Post #5

New D.I.C Head
*

Joined: 17 Mar, 2008
Posts: 7

QUOTE(Amadeus @ 17 Mar, 2008 - 12:13 PM) *

You appear to have one more opening brace that you do closing braces. I'd go though the code tracking the sets of {}, and see where the missing one is.


I found that the open '{' below int main() was never closed. I closed it at the end of the program but now I am getting three errors about my void displaygrader();
void displaycalculator();

User is offlineProfile CardPM
+Quote Post

Amadeus
RE: C++ Homework Error Problem
17 Mar, 2008 - 11:38 AM
Post #6

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,228



Thanked: 40 times
Dream Kudos: 25
My Contributions
Can you please post the errors you are receiving?
User is offlineProfile CardPM
+Quote Post

asiandoll
RE: C++ Homework Error Problem
17 Mar, 2008 - 11:48 AM
Post #7

New D.I.C Head
*

Joined: 17 Mar, 2008
Posts: 7

QUOTE(Amadeus @ 17 Mar, 2008 - 12:38 PM) *

Can you please post the errors you are receiving?


Errors are as follows:

1. unresolved external symbol "void_cdecl displaycalculator(void)" (?displaycalculator@@YAXXZ) referenced in function_main

2. unresolved external symbol "void_cdecl displaygrader(void)" (?displaygrader@@YAXXZ) referenced in function_main

3. 2 Unresolved externals
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: C++ Homework Error Problem
17 Mar, 2008 - 11:54 AM
Post #8

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,228



Thanked: 40 times
Dream Kudos: 25
My Contributions
Well, you have referenced two functions, but you've never actually written or defined those functions anywhere. Where are the definitions for displaycalculator() and displaygrader()?
User is offlineProfile CardPM
+Quote Post

asiandoll
RE: C++ Homework Error Problem
17 Mar, 2008 - 12:08 PM
Post #9

New D.I.C Head
*

Joined: 17 Mar, 2008
Posts: 7

QUOTE(Amadeus @ 17 Mar, 2008 - 12:54 PM) *

Well, you have referenced two functions, but you've never actually written or defined those functions anywhere. Where are the definitions for displaycalculator() and displaygrader()?


Can you please help me on where I am suppose to define these functions?
User is offlineProfile CardPM
+Quote Post

asiandoll
RE: C++ Homework Error Problem
17 Mar, 2008 - 12:27 PM
Post #10

New D.I.C Head
*

Joined: 17 Mar, 2008
Posts: 7

QUOTE(Amadeus @ 17 Mar, 2008 - 12:54 PM) *

Well, you have referenced two functions, but you've never actually written or defined those functions anywhere. Where are the definitions for displaycalculator() and displaygrader()?


I inserted it into my code can you please check to see if it is correct?

CODE

#include<iostream>
    #include<iomanip>


    using std::cout;
    using std::cin;
    using std::endl;
    using std::setprecision;
    using std::ios;
    using std::setiosflags;

void displaygrader();
void displaycalculator();
    

int main()


    {
        int choice;
        int  left, right;
        int Enter1;
        int Enter2;
        char oper;          
        int  result;        
        char name[50];
        char Class[100];
        char Section[100];            
        int    average,
            a,
            b,
            c,
            d,
            f,
            n,
            sum,
            gpa,
            grade,                    
            gradeCounter,
            total;
            
            
        
        //initialization phase
        n=1;
        grade=0;
        gradeCounter=n;
        total=0;
        a=4;
        b=3;
        c=2;
        d=1;
        f=0;                        //prepare to loop
        
        
        
          //display output in fixed-point notation
    //with two decimal places
        cout <<setiosflags (ios::fixed) <<setprecision(2);
        
        
        // processing phase
        cout<<"Welcome to my program"<<endl;
        cout<<endl;
        cout<<endl;
        cout<<"What is your name? I would prefer it, if you entered only your first name"<<endl;
        cin>>name;
        cout<<"So tell me "<<name<< "Which program would like to use the Grader or the Calculator"<<endl;
        cout<<endl;
        do
        {
        cout<<"1      Display grader"<<endl;
        cout<<"2      Display calculator"<< endl;
        cout<<"3      End program" <<endl;
        cout<<"Enter your choice: ";
        cin>> choice;
        if (choice == 1)
            displaygrader();
            else if(choice == 2)
                displaycalculator();    

void displaygrader()
{
        cout<<"What class are you in"<<endl;
        cin>>Class;
        cout<<"What section are you in then "<<name<<endl;
        cin>>Section;
        cout<<endl;
        cout<<endl;
        cout<<"Okay enough of information. It's time to calculate your grades"<<endl;
        cout<<endl;
        cout<<endl;
        cout<<"Please enter the number of grades to be calculated:    "<<endl;
        cin>>n;
        }
    
        //loop statment
        while (gradeCounter <= n); {    
            cout<<"Please enter grade: ";    
            cin>>grade;                        
            
            total=total + grade;            
            gradeCounter= gradeCounter + 1;    
            }//end while



        
        
            
            //Calculation of the problem
            average=total/n;
            sum=total+grade;
            cout<<"Your average is "<<average<<"%"<<endl;
            cout<<"The sum of your scores is "<<sum<<endl;
            cout<<endl;
            cout<<endl;

            
            
            
            

                if (average>=84) {
                    cout<<"You received an A in the course! good job!"<<endl;
                    cout<<endl;
                    cout<<"Keep up the good work!"<<endl;
                    
                }
                    else if(average>=66) {
                    cout<<"You receieved a B in the course! keep up the good work!"<<endl;
                    cout<<endl;
                    cout<<endl;
                        
                    }
                        else if (average>=50) {
                        cout<<"You received a C in the course. You need improvement!"<<endl;
                        cout<<endl;
                        cout<<"You can do better!"<<endl;
                            
                        }
                            else if (average>=45) {
                            cout<<"You received a D! that is terrible!"<<endl;
                            cout<<endl;
                            
                                
                            }
                                else if (average<=44 && average >=0) {
                                cout<<"You received an F! Im sorry but you have to take the course again!"<<endl;
                                cout<<endl;
                                    
                    }
                            // GPA Statment
                            gpa=average/n;
                            if (average>=84)
                                cout<<"You gpa is: 4.0"<<endl;
                            else if (average>=66)
                                cout<<"Your gpa is: 3.75"<<endl;
                            else if (average>=50)
                                cout<<"Your gpa is: 2.00"<<endl;
                            else if (average>=45)
                                cout<<"Your gpa is: 1.00"<<endl;
                                else
                   cout<<"You failed study harder and push your gpa up!"<<endl;
                            cout<<endl;
                            cout<<endl;
                            cout<<endl;
}
                            
  void displaycalculator()
{    
    while (cin >> left >> oper >> right) {
        switch (oper) {
            case '+': result = left + right;
                      break;
            case '-': result = left - right;
                      break;
            case '*': result = left * right;
                      break;
            case '/': result = left / right;
                      break;
            default : cout << "Bad operator '" << oper << "'" << endl;
                      
                cout << result << endl << endl;
        }

        return 0;
    }

}
}


User is offlineProfile CardPM
+Quote Post

asiandoll
RE: C++ Homework Error Problem
17 Mar, 2008 - 02:37 PM
Post #11

New D.I.C Head
*

Joined: 17 Mar, 2008
Posts: 7

With the following code I have seven (7) errors:

Can someone please help...


1>test.cpp
1>c:\documents and settings\asiandoll\my documents\visual studio 2005\projects\test\test\test.h(83) : error C2601: 'displaygrader' : local function definitions are illegal
1> c:\documents and settings\asiandoll\my documents\visual studio 2005\projects\test\test\test.h(71): this line contains a '{' which has not yet been matched
1>c:\documents and settings\asiandoll\my documents\visual studio 2005\projects\test\test\test.h(170) : error C2062: type 'void' unexpected
1>c:\documents and settings\asiandoll\my documents\visual studio 2005\projects\test\test\test.h(171) : error C2143: syntax error : missing ';' before '{'
1>c:\documents and settings\asiandoll\my documents\visual studio 2005\projects\test\test\test.h(85) : error C2065: 'Class' : undeclared identifier
1>c:\documents and settings\asiandoll\my documents\visual studio 2005\projects\test\test\test.h(86) : error C2065: 'name' : undeclared identifier
1>c:\documents and settings\asiandoll\my documents\visual studio 2005\projects\test\test\test.h(87) : error C2065: 'Section' : undeclared identifier
1>c:\documents and settings\asiandoll\my documents\visual studio 2005\projects\test\test\test.h(94) : error C2065: 'n' : undeclared identifier
1>Generating Code...
1>Build log was saved at "file://c:\Documents and Settings\Asiandoll\My Documents\Visual Studio 2005\Projects\test\test\Debug\BuildLog.htm"
1>test - 7 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


CODE

#include<iostream>
    #include<iomanip>


    using std::cout;
    using std::cin;
    using std::endl;
    using std::setprecision;
    using std::ios;
    using std::setiosflags;

void displaygrader();
void displaycalculator();
    

int main()


    {
        int choice;
        int  left, right;
        int Enter1;
        int Enter2;
        char oper;          
        int  result;        
        char name[50];
        char Class[100];
        char Section[100];            
        int    average,
            a,
            b,
            c,
            d,
            f,
            n,
            sum,
            gpa,
            grade,                    
            gradeCounter,
            total;
            
            
        
        //initialization phase
        n=1;
        grade=0;
        gradeCounter=n;
        total=0;
        a=4;
        b=3;
        c=2;
        d=1;
        f=0;                        //prepare to loop
        
        
        
          //display output in fixed-point notation
    //with two decimal places
        cout <<setiosflags (ios::fixed) <<setprecision(2);
        
        
        // processing phase
        cout<<"Welcome to my program"<<endl;
        cout<<endl;
        cout<<endl;
        cout<<"What is your name? I would prefer it, if you entered only your first name"<<endl;
        cin>>name;
        cout<<"So tell me "<<name<< "Which program would like to use the Grader or the Calculator"<<endl;
        cout<<endl;
        do
        {
        cout<<"1      Display grader"<<endl;
        cout<<"2      Display calculator"<< endl;
        cout<<"3      End program" <<endl;
        cout<<"Enter your choice: ";
        cin>> choice;
        if (choice == 1)
            displaygrader();
            else if(choice == 2)
                displaycalculator();    

void displaygrader()
{
        cout<<"What class are you in"<<endl;
        cin>>Class;
        cout<<"What section are you in then "<<name<<endl;
        cin>>Section;
        cout<<endl;
        cout<<endl;
        cout<<"Okay enough of information. It's time to calculate your grades"<<endl;
        cout<<endl;
        cout<<endl;
        cout<<"Please enter the number of grades to be calculated:    "<<endl;
        cin>>n;
        }
    
        //loop statment
        while (gradeCounter <= n); {    
            cout<<"Please enter grade: ";    
            cin>>grade;                        
            
            total=total + grade;            
            gradeCounter= gradeCounter + 1;    
            }//end while



        
        
            
            //Calculation of the problem
            average=total/n;
            sum=total+grade;
            cout<<"Your average is "<<average<<"%"<<endl;
            cout<<"The sum of your scores is "<<sum<<endl;
            cout<<endl;
            cout<<endl;

            
            
            
            

                if (average>=84) {
                    cout<<"You received an A in the course! good job!"<<endl;
                    cout<<endl;
                    cout<<"Keep up the good work!"<<endl;
                    
                }
                    else if(average>=66) {
                    cout<<"You receieved a B in the course! keep up the good work!"<<endl;
                    cout<<endl;
                    cout<<endl;
                        
                    }
                        else if (average>=50) {
                        cout<<"You received a C in the course. You need improvement!"<<endl;
                        cout<<endl;
                        cout<<"You can do better!"<<endl;
                            
                        }
                            else if (average>=45) {
                            cout<<"You received a D! that is terrible!"<<endl;
                            cout<<endl;
                            
                                
       &