Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6734429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:53:15+00:00 2026-05-26T10:53:15+00:00

Hello to all that read I have a small problem(or it could be large!),

  • 0

Hello to all that read

I have a small problem(or it could be large!), just one error at compile time but as we all know one error is all it takes to hinder progress.
Basically I am fairly new to C++ and have been tasked with writing the following code and passing by value a type stuct argument to the function. But I get the following error message:
“two or more data types in declaration of average” so any solution/s to my one error would be much appreciated.
Many thanks in advance…

enter code here
#include <iostream> 
#include <cstdio>
#include <math.h>
using namespace std;


           struct student{

              char name[40];
              int student_id;
              int student_grades[3];
              int average;
           };

int main ()
{
   extern int average(student);
   student programming;

   int j;

         cout<<"\nPlease Enter the student name for student number: ";

         cin>>programming.name;

         cout<<"\nPlease Enter student i.d for student number: ";

         cin>>programming.student_id;

         cout<<"\nPlease Enter student grades for student number: ";

         for(j=0;j<3;j++){

                    cout<<"\nEnter student grade no: "<<j+1<<"\n";
                    cin>>programming.student_grades[j];               
         }

         programming.average=average(programming);

         cout<<"\nNo.      Name      ID Number      Average\n";
         cout<<programming.name;
         cout<<"      "<<programming.student_id <<"      ";
         cout<<programming.average<<"      ";             

     system ("PAUSE");
     return 0;
}

struct student;
int void average(student programming){

    int sum=0;
    int ave=0;
    int j;

    for(j=0;j<3;j++){
           sum=sum+programming.student_grades [j];
    }
    ave=sum/3;
    return ave;
}
enter code here
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:53:15+00:00Added an answer on May 26, 2026 at 10:53 am

    See this?

    int void average(student programming){
    

    That’s “two or more types” in a row, in the part where you say what the return type is for the function. Make up your mind.

    There are several other problems with your code, mostly just stylistic. You don’t want your function declaration to be extern (since it’s right there in the same file); you want that declaration to be outside of main (it will work inside, but there’s really no point); you don’t need math.h (which is a C header anyway); you should be using a real string type to represent strings; storing the grade average back into the structure isn’t especially useful (you already have it, so just use it directly); and several of your variable names don’t make any sense (programming is an especially obvious example).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hello all I have a small dialog which I created dynamically, which has a
Problem Hello all! I have this code which takes my jpg image loops through
I have read through all relevant posts on Prawn but found no mentioning (even
hello i have a problem that's maybe difficult to descripe, i have an application,
Hello to all that read I am self learning C++ from a text book.
Hello to all that read I am self learning C++ from a text book:
Hello all i have a simple problem i have a alertDialog and i want
This has to be a common question that all programmers have from time to
Hello all i have a quick question Is there a way i could make
im messing with the encodings. For one hand i have a url that is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.