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 question.(5)

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

ITtutoria

ITtutoria Logo ITtutoria Logo

ITtutoria Navigation

  • Python
  • Java
  • Reactjs
  • JavaScript
  • R
  • PySpark
  • MYSQL
  • Pandas
  • QA
  • C++
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA
Home/ Questions/Amazing solutions for the c++: ''Expression must have integral or unscoped enum type'' error.
Next
Answered
Reyna Jones
  • 33
Reyna Jones
Asked: May 18, 20222022-05-18T18:35:54+00:00 2022-05-18T18:35:54+00:00In: cpp

Amazing solutions for the c++: ”Expression must have integral or unscoped enum type” error.

  • 33

. Advertisement .

..3..

. Advertisement .

..4..

I get an error:

expression must have integral or unscoped enum type.

when I try to run the following code:

#include <iostream>
 #include <iomanip>
 #include <string>
 #include <algorithm>
 #include <sstream>
 
 using namespace std;
 
 int main(){
 
  float size;
 
  float sumNum = 0;
  float maxNum, minNum;
  float mean;
  float totalDev = 0;
  float devSqr = 0;
  float stdDev;
 
  //Create a user input size
  std::cout << "How many number would you like to enter? ";
  std::cin >> size;
  float *temp = new float[size];
 
  //Getting input from the user
  for (int x = 1; x <= size; x++){
  cout << "Enter temperature " << x << ": ";
  cin >> temp[x];
  }
 
  //Output of the numbers inserted by the user
  cout << endl << "Number --- Temperature" << endl << endl;
  for (int x = 1; x <= size; x++){
  cout << " " << x << " --- " << temp[x] << endl;
  sumNum = sumNum + temp[x];
  }
 
  //Calculating the Average
  mean = sumNum / size;
  maxNum = minNum = temp[1];
 
  for (int x = 1; x <= size; x++){
  if (maxNum < temp[x]){
  maxNum = temp[x];
  }
  if (minNum > temp[x]){
  minNum = temp[x];
  }
  }
 
  //Calculating Sample Standard Deviation
  for (int x = 1; x <= size; x++){
  totalDev = totalDev + (temp[x] - mean);
  devSqr = devSqr + (pow((temp[x] - mean), 2));
  }
  stdDev = sqrt((devSqr / (size - 1)));
 
  cout << endl << "The sum: " << sumNum << endl; //the sum of all input
  cout << "The mean: " << mean << endl; //calculate the average 
  cout << "Maximum number: " << maxNum << endl; // print biggest value
  cout << "Minimum number: " << minNum << endl; // print smallest value
  cout << "The range between the maximum and the minimum: " << maxNum - minNum << endl; //the range
  cout << "Deviation: " << totalDev << endl;
  cout << "The squares of deviation: " << devSqr << endl;
  cout << "The Standard Deviation: " << setprecision(1) << fixed << stdDev << endl;
 
  system("pause");
 }

How to fix the c++ expression must have integral or unscoped enum type. Please give me some good ideas.

  • 1 1 Answer
  • 194 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Best Answer
    lyytutoria Expert
    2022-06-16T01:10:09+00:00Added an answer on June 16, 2022 at 1:10 am

    The cause:

    After researching your error for hours, I found that the size of your variable is expressed as float size. However, the size of an array cannot be a floating point variable, it must be an integer value.

    Another issue is perhaps caused by writing outside the array’s bounds:

    float *temp = new float[size];
    
    //Getting input from the user
    for (int x = 1; x <= size; x++){
    cout << "Enter temperature " << x << ": ";
    
    // cin >> temp[x];
    // This should be:
    cin >> temp[x - 1];
    }

    Because C++ arrays are zero-based, this will write past the end of the array and never write the first element in your original function.

    These are the cause of your error.

    Solution:

    To solve this error, you have to replace float size by an integer value.

    float *temp = new float[(int)size];

    And remember not to write outside the limits of the array.

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

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question
  • How to Split String by space in C++
  • How To Convert A Pandas DataFrame Column To A List
  • How to Replace Multiple Characters in A String in Python?
  • How To Remove Special Characters From String Python

Explore

  • Home
  • Tutorial

Footer

ITtutoria

ITtutoria

This website is user friendly and will facilitate transferring knowledge. It would be useful for a self-initiated learning process.

@ ITTutoria Co Ltd.

Tutorial

  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA

Legal Stuff

  • About Us
  • Terms of Use
  • Privacy Policy
  • Contact Us

DMCA.com Protection Status

Help

  • Knowledge Base
  • Support

Follow

© 2022 Ittutoria. All Rights Reserved.

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.