473,509 Members | 2,526 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Receiving error on a simple code and don't understand why?

1 New Member
I need to find the max of the values using an array. For some reason I receive this error:

error: invalid types `float[9][float]' for array subscript

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.  
  7.   const int SLOPES = 9;
  8.   float nums[SLOPES] = {17.24, 25.63, 5.94, 33.92, 3.71, 32.84, 35.95, 18.24, 6.92};
  9.  
  10.   float i, max = nums[0];
  11.  
  12.   for (i = 1; i < SLOPES; i++)
  13.     if (max < nums[i])
  14.      max = nums[i];
  15.  
  16.   cout << "The maximum value is " << max << endl;
  17.  
  18.  return 0;
  19. }
  20.  
Apr 12 '12 #1
1 1229
weaknessforcats
9,208 Recognized Expert Moderator Expert
Array indexes must be integers. Element 4 or 5 makes sense but element 2.57 doesn't.

Your variable i needs to be an int.
Apr 12 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

20
2532
by: Sam | last post by:
Hi I'm learning to code with C++ and wrote some very simple code. I think it's consistent with every rule but always got compiling errors that I don't understand. The code include 5 files as...
11
4705
by: Polar | last post by:
Hi! i'm a newbie in C language and i'm writing my first simple codes. In one of these, my purpose is to append the ascii value of an interger (example 101 --> e) at the end of a string to...
1
1699
by: Merrua | last post by:
I dont understand how to do this I created a dialog based project and that is fine for most of my programming project, but one dialog box is going to generate a graph, and as far as i know from...
4
1301
by: VB Programmer | last post by:
In 1.1 if I made a simple code change I would just copy the dll in the bin folder to the website and that's it. If I make a simple code change in 2.0 what file(s) would I need to copy to the web...
3
1911
by: Sheau Wei | last post by:
This is the code the code that i try to run it as my search engine for my database. But i dont understand why i run a notice that undefind index. Can u help me ? <form method="post"...
5
1819
by: ryann18 | last post by:
I was just wondering, my teacher assigned a project for me and told me to "create one cat in SandBox and put all the methods (for example method_1) you need for the excercises in KittyKitty and call...
19
2226
by: so many sites so little time | last post by:
the table is head the colunm is called body <?php //show_site.php // This script retrieves blog entries from the database. // Address error handing. ini_set ('display_errors', 1);...
10
1795
by: Sourcerer | last post by:
I wrote this very simple code in .NET VC++. I compiled it on my system, and tried to run it on my friend's computer (he doesn't have the compiler). We both have Windows XP Professional. I have .NET...
30
3472
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
3
2428
by: canabatz | last post by:
Hello all!! i got a small problem ,not big :) i got this example of a link in my site that display everything correctly! http://www.mysite.com/product.php?id=200 now my problem is : if...
0
7233
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7135
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7342
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5650
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4729
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
774
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
440
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.