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 6668249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:01:17+00:00 2026-05-26T03:01:17+00:00

I am getting a segmentation fault in console while running the program i am

  • 0

I am getting a segmentation fault in console while running the program
i am using codeblocks in ubuntu(linux)

it compiles with 0 errors and 0 warnings

code in pastebin
http://pastebin.com/wgSHPQjc

here is the code

#include <iostream>
#include <string>
using namespace std;

class Year
{
    public:

Year(string sone, string stwo, string sthree, string sfour, string sfive, string ssix, string sseven, string seight)  // constructor
{
        subjectName[0] = sone;
        subjectName[1] = stwo;
        subjectName[2] = sthree;
        subjectName[3] = sfour;
        subjectName[4] = sfive;
        subjectName[5] = ssix;
        subjectName[6] = sseven;
        subjectName[7] = seight;

        sum = 0;
        percentage = 0;
}
void nameOfSem(string semName) // semster name
{
    name = semName;
    cout << "Enter your " << name  << " marks"<< endl;
}
//no of subjects in semster and  store marks in an array
void readMarks(int noOfSubjects)
{
    subjects = noOfSubjects;
    for(int i=0; i<subjects; i++)
    {
        cout << subjectName[i]; // print out subject name stored in the array
        cin >> yearName[i]; // input from keyboard of marks
        // while loop so that user enters marks from 0 to 100
        while (yearName[i]<0 || yearName[i] > 100 )
        {
            cout << "incorrect input please enter again: ";
            cin >> yearName[i];
        }
    }
}

// function for calculating avarage
void avarage()
{
    for(int j=0; j<subjects; j++) // addtion of marks (addtion of array)
    {
        sum += yearName[j];
    }
    cout << "the total  is : " << sum << endl;
    percentage = float(sum) / float(subjects);
    cout << "The percentage is :  " << percentage << endl;
}

            int sum; // for storing sum of marks

            string name; //  for storing name of the semister
            int subjects; // for storing number of subjects in semister
            float percentage; // calculating percentage in the sem
             int yearName[]; // array for string marks
             string subjectName[]; // array for storin g subject names

};


// main function
int main()
{
    cout << "Welcome to xxx uni " << endl;

  // constructor for storing subjects name in the array
   Year first("Appiled Physics ", "Electronic Devices circuits ", "Basic electrical Engineering ", "C & Data Structures", "English ", "Mathematical Methods ", "mathematics 1 ", "Engineering Drawing ");

  // name of the sem
   first.nameOfSem("First Year");

   //no of subjects and storing marks in the array
   first.readMarks(8);

   //calculating avarage
   first.avarage();




/*
   Year two( " " , " ", " ")
   second year object

   */
    return 0;
}
  • 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-26T03:01:17+00:00Added an answer on May 26, 2026 at 3:01 am
    int yearName[]; // array for string marks
    string subjectName[]; // array for storin g subject names
    

    These two lines should NOT compile if your compiler is Standard conformant.

    Use std::vector :

    std::vector<int> yearName;
    std::vector<string> subjectName;
    

    And then use push_back function to add elements to them.

    Year(string sone, string stwo, string sthree, /*...*/)  
    {
            subjectName.push_back(sone);
            subjectName.push_back(stwo);
            subjectName.push_back(sthree);
            //so on    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting a segmentation fault while running this code. I can't work out
I am getting a Segmentation Fault error when running my program in GCC. This
I am getting segmentation fault in this code but i cant figure out why.
I have a process in Linux that's getting a segmentation fault. How can I
I am getting a segmentation fault with the following code after adding structs to
I'm getting a segmentation fault trying to compile the following code. My question is,
I have a C program below written on UNIX. I am getting segmentation fault.
I've a 'C' program which has encountered a strange problem.. I'm getting segmentation fault
Im working on this bit of code and I keep getting a segmentation fault.
Im getting segmentation fault from pthread_mutex_lock, heres my backtrace: Program received signal SIGSEGV, Segmentation

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.