GIDForums  

Go Back   GIDForums > Computer Programming Forums > CPP / C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 31-Jan-2005, 23:46
xellos16 xellos16 is offline
New Member
 
Join Date: Jan 2005
Posts: 3
xellos16 is on a distinguished road

A little help with some code


I am attempting to do a grade average program for class, and its my first one. So I know that there are tons of errors, so if you guys could pick the code apart and offer help, I would be most thankful

CPP / C++ / C Code:
//***************************************************
// Filename: Assignment.cpp
// Author: Bilal Lang
// Date Created: January 27, 2005
// Purpose: TO create a program that will find the average of grades
//********************************************************************

#include <iostream>

using namespace std;

const unsigned int MAX_ASSIGNMENTS = 7;

// Function prototypes
void getScoreData (unsigned int &examOneScore, unsigned int &examTwoScore,
                   unsigned int assignmentScores[]);
float calculateFinalScore (unsigned int examOneScore, unsigned int examTwoScore,
                                   unsigned int assignmentScores[]);
void displayFinalScoreAndGrade (float finalScore);

//***************************************************************************
int main (void)
{
    unsigned int examOne;
    unsigned int examTwo;
    unsigned int assignments [MAX_ASSIGNMENTS];
    float finalScoreValue;
    
    cout << "\n*** Final Score Program ***"  << endl;
    
    getScoreValue = calculateFinalScore (examOne, examTwo, assignments);
    
    displayFinalScoreAndGrade (finalScoreValue);
    
    cout << "\n*** End of Final Score Program ***" << endl;
    
    return 0;
}// End main
//****************************************************************************
unsigned int examOneScore ()
{
cout << "Enter score for Exam #1 (0-100): ";
cin >> examOneScore;
} //End examOneScore
//****************************************************************************
unsigned int examTwoScore ()
{
         cout << "Enter score for Exam #2 (0-100): ";
         cin >> examTwoScore;
         }
         //End examTwoScore
//*****************************************************************************
unsigned int assignmentScores ()

{
int num1;
int num2;
int num3;
int num4;
int num5;
int num6;
int num7;       

         cout << "Enter score for Assignment #1 (0-10): ";
         cin >> num1;
         cout << "Enter score for Assignment #2 (0-10): ";
         cin >> num2;
         cout << "Enter score for Assignment #3 (0-10): ";
         cin >> num3;
         cout << "Enter score for Assignment #4 (0-10): ";
         cin >> num4
         cout << "Enter score for Assignment #5 (0-10): ";
         cin >> num5;
         cout << "Enter score for Assignment #6 (0-10): ";
         cin >> num6;
         cout << "Enter score for Assignment #7 (0-10): ";
         cin >> num7;
         
         unsigned int assignmentScores = (num1 + num2 +num3 + num4 + num5+ num6 
                                          + num7)/7;
} //End assignmentScores
//************************************************************************************
float finalScore ()
{
      float finalScore = (assignmentScores + examScoreOne + examScoreTwo)/3;
}
//***********************************************************************************

void displayFinalScoreAndGrade ()
{
cout << endl << " << finalScore <<" endl;
}
Last edited by LuciWiz : 01-Feb-2005 at 01:26. Reason: Please insert your C code between [c] & [/c] tags
  #2  
Old 01-Feb-2005, 08:01
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,617
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by xellos16

...
there are tons of errors
...

The way it works is:
1. It's your assignment --- you should work through the errors and fix them.

2. If you have any specific questions about the errors (don't know what a particular error message means or don't understand why it's an error), post the exact error message (paste directly into the post).

3. If you have any specific questions about language constructs or usage: ask.

4. If something doesn't work the way you think it should: tell us what your input to the program was, what you expected to get, and what you got. Be specific.

Regards,

Dave
  #3  
Old 01-Feb-2005, 08:43
xellos16 xellos16 is offline
New Member
 
Join Date: Jan 2005
Posts: 3
xellos16 is on a distinguished road
Sorry, I am looking at correcting this statment.


error C2296: '+' : illegal, left operand has type 'unsigned int (__cdecl *)(void)'

for this line
Code:
int finalScore () { int finalScore = (assignmentScores) + ( examOne + examTwo); }
  #4  
Old 01-Feb-2005, 09:40
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,617
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by xellos16
Sorry, I am looking at correcting this statment.


error C2296: '+' : illegal, left operand has type 'unsigned int (__cdecl *)(void)'

for this line
Code:
int finalScore () { int finalScore = (assignmentScores) + ( examOne + examTwo); }

1. finalScore is the name of a function.

2. You can't declare a new variable with the same name.

3. Here's what the error message was more-or-less trying to say: When you use the name of a function in an expression, the compiler interprets it as a pointer to the location of the function. The address can't be used on the left hand side of an assignment (since it's constant and can't be changed by the program).

Maybe you meant something like:
CPP / C++ / C Code:
int finalScore ()
{
      return  assignmentScores +  examOne + examTwo;
}

Note that in order to use this, the variables assignmentScores, examOne, and examTwo must be within the scope of the function finalScore(). The proper way to do this is to pass them as arguments. This is not BASIC (where traditionally everything is global), it's C.

Regards,

Dave
  #5  
Old 01-Feb-2005, 10:56
xellos16 xellos16 is offline
New Member
 
Join Date: Jan 2005
Posts: 3
xellos16 is on a distinguished road
Thanks, I have it pretty much done except for one part:

'main' : missing storage-class or type specifiers

This is my main here

CPP / C++ / C Code:
int main(void)
{
  unsigned int examOne;
  unsigned int examTwo;
  unsigned int assignments[MAX_ASSIGNMENTS];
  float finalScoreValue;

  cout << "\n*** Final Score Program ***" << endl;

  getScoreData(examOne, examTwo, assignments);

  finalScoreValue = calculateFinalScore(examOne, examTwo, assignments);

  displayFinalScoreAndGrade(finalScoreValue);

  cout << "\n*** End of Final Score Program ***" << endl;

  return 0;
} // End main

I also recieve this warning.
'int ' : storage-class or type specifier(s) unexpected here; ignored

These are my 'last' questions. Thanks!!!
Last edited by LuciWiz : 26-Mar-2006 at 08:58. Reason: Please insert your C++ code between [c++] & [/c++] tags
  #6  
Old 01-Feb-2005, 11:37
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,617
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by xellos16
Thanks, I have it pretty much done except for one part:

'main' : missing storage-class or type specifiers



I also recieve this warning.
'int ' : storage-class or type specifier(s) unexpected here; ignored


I don't see anything in this last code for main() that could cause these symptoms. The code in your first post had lots of problems. If you are now only getting these two messages, you must have changed quite a bit. I think you need to post your most recent complete code (assuming it's not too much bigger that our original).

Regards,

Dave
  #7  
Old 06-Feb-2005, 09:50
ubergeek ubergeek is offline
Regular Member
 
Join Date: Jan 2005
Posts: 775
ubergeek is a jewel in the roughubergeek is a jewel in the roughubergeek is a jewel in the rough
Quote:
Originally Posted by xellos16
Sorry, I am looking at correcting this statment.


error C2296: '+' : illegal, left operand has type 'unsigned int (__cdecl *)(void)'

for this line
Code:
int finalScore () { int finalScore = (assignmentScores) + ( examOne + examTwo); }

you can't add return values of functions without calling the functions (which you are doing wrong). try this:

CPP / C++ / C Code:
int finalScore()
{
return assignmentScores() + examOne() + examTwo();
}
 

Recent GIDBlogNARMY by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Formatting C / C++ code WaltP C Programming Language 1 06-Jan-2008 23:59
Problem with int mixed with char,... leitz CPP / C++ Forum 17 07-Dec-2004 20:56
Help! Some basal questions about MFC xutingnjupt MS Visual C++ / MFC Forum 1 05-Dec-2004 03:38
very difficult code - program gaurav_sting CPP / C++ Forum 1 16-Jun-2004 00:59

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 16:18.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.