Author Topic: i have had this code but i get the error subscript is not of integral type  (Read 4809 times)

0 Members and 1 Guest are viewing this topic.

Offline lubzy95

  • ZX 81
  • *
  • Posts: 5
  • Karma: 0
    • View Profile
#pragma once
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>
using namespace std;

int main()
{
   //declare an array
   float numbers [10];
   double sum;
   double mean;
   double standardDeviation;
   double AA;
   double sdresult;
   double mode;
   double max;
   double modeposition;

   //storing 30 numbers entered by user in an array
   cout<<"enter thirty floating point numbers"<<endl;

   //compute sum, mean and standard deviation
   for (int i = 0; i < 10; ++i)
   {
        cin >> numbers;
        sum += numbers;
      mean = sum /10;
      AA += pow(numbers - mean,2);
      max= numbers;
      modeposition = i;
    }
   sdresult = sqrt(AA/10);
   mode = numbers[modeposition];
   cout<<"sum="<<sum <<endl;
   cout<<"mean="<<mean <<endl;
    cout<<"standard Deviation = " <<sdresult<<endl;
   cout<<"mode="<<mode<<endl;

   return 0;
}

Offline lubzy95

  • ZX 81
  • *
  • Posts: 5
  • Karma: 0
    • View Profile
please assist me on where i might be going wrong
thank you in advance

Offline lubzy95

  • ZX 81
  • *
  • Posts: 5
  • Karma: 0
    • View Profile
Re: output console disappearing
« Reply #2 on: May 30, 2017 »
#pragma once
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>
using namespace std;

int main()
{
   //declare an array
   float numbers [10];
   double sum;
   double mean;
   double standardDeviation;
   double AA;
   double sdresult;
   double mode;
   double max;
   double modeposition;

   //storing 30 numbers entered by user in an array
   cout<<"enter thirty floating point numbers"<<endl;

   //compute sum, mean and standard deviation
   for (int i = 0; i < 10; ++i)
   {
        cin >> numbers;
        sum += numbers;
      mean = sum /10;
      AA += pow(numbers - mean,2);
      max= numbers;
      modeposition = i;
    }
   sdresult = sqrt(AA/10);
   cout<<"sum="<<sum <<endl;
   cout<<"mean="<<mean <<endl;
    cout<<"standard Deviation = " <<sdresult<<endl;
   cout<<"mode="<<modeposition<<endl;

   return 0;
}

Offline lubzy95

  • ZX 81
  • *
  • Posts: 5
  • Karma: 0
    • View Profile
i have managed to get it running but the moment i click enter after entering my last value in the console, the console just disappears
please help me out thank you

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Hi,

You have problems with uninitialized variables "sum" and "AA" and errors using the array "numbers".

Try this out:

Code: [Select]
#include <iostream>
#include <cmath>
#include <fstream>
using namespace std;

int main()
{
   //declare an array
   float numbers[10];
   double sum;
   double mean;
   double standardDeviation;
   double AA;
   double sdresult;
   double mode;
   double max;
   double modeposition;

   sum = 0;
   AA = 0;

   //storing 30 numbers entered by user in an array
   cout<<"enter thirty floating point numbers"<<endl;

   //compute sum, mean and standard deviation
   for (int i = 0; i < 10; ++i)
   {
        cin >> numbers[i];
        sum += numbers[i];
      mean = sum /10;
      AA += pow(numbers[i] - mean,2);
      max= numbers[i];
      modeposition = i;
    }
   sdresult = sqrt(AA/10);
   cout<<"sum="<<sum <<endl;
   cout<<"mean="<<mean <<endl;
    cout<<"standard Deviation = " <<sdresult<<endl;
   cout<<"mode="<<modeposition<<endl;

   return 0;
}
Challenge Trophies Won:

Offline lubzy95

  • ZX 81
  • *
  • Posts: 5
  • Karma: 0
    • View Profile
hi
i get the same issue the console disappears after i enter the last value