Overloaded function?

Hello, for my code I am trying to run it and make a proper table, but an error pops up saying that my "time=.." line is an overloaded function. Any advice?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include<iostream> //Required for cout prog 4_5!

#include<cmath>

#include<iomanip>

using namespace std;


int main()



{

double increment,final_time,initial,time,max_altitude(0),altitude,max_time(0),count;  //Declare and initialize objects

   int loops;

cout << "Hello User! Enter the initial time in hours from 0 to 23\n "; //Telling the user what it's about and what to put in.

cin >> initial;

cout << "Next enter the increment steps of time in hours from 0 to 23\n ";

cin >> increment;

cout << "Now the final time from 0 to 23 hrs \n";

cin >> final_time;

cout << "\n\n Drone Altitude Table\n";
cout << "Time(hrs)      Altitude(meters)\n";
cout << "____________________________\n";

cout.setf(ios::fixed);
cout<<setprecision(5);


 for ( int count = 0;  count <= loops ; ++count)
 loops = (int)( (final_time - initial) / increment ); //Declaring loop variable
{
    time = initial + count * increment;
    altitude =-0.12 * pow(time, 4) + 12.1 * pow(time,3) - 360 * pow(time, 2) + 3910 * time;  // Our equation we wiil be working with


    cout<< setw(6) << time << setw(6) << altitude << endl;// For more accurate results


    if (altitude > max_altitude)

    {

    altitude = max_altitude;
    max_time = time;

    }



    cout << "\nThe maximum altitude of the drone was " << setw(8) << max_altitude << "meters \n" << endl;
    cout << "and it reached it's maximum altitude at " << setw(6) << max_time << "hrs \n" << endl;


}
return 0;



}
Last edited on
1. Format your code - https://www.cplusplus.com/articles/jEywvCM9/

2. time is the name of an existing library function.
Pick a different name.
I get an error on count on that line because it is undefined.
1
2
3
4
for ( int count = 0; count <= loops ; ++count)
loops = (int)( (final_time - initial) / increment ); //Declaring loop variable
{
time = initial + count * increment;

Note that your for loop only applies to the next line.
Consequently, count is out of scope on line 4.
Is your open bracket in the wrong place?

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.

Also, get rid of the double and triple spacing. It makes you code hard to read.
The issue was a semicolon at the end of the for loop and I defined count in the :double" section. It now runs, but it will not give me a table and the max_altitude stays at zero for some reason.
Why indentation matters!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<iostream>              //Required for cout prog 4_5!
#include<cmath>
#include<iomanip>
using namespace std;

int main()
{
  double increment, final_time, initial, time, max_altitude(0), 
         altitude, max_time(0), count; //Declare and initialize objects

  int loops;

  cout << "Hello User! Enter the initial time in hours from 0 to 23\n ";  //Telling the user what it's about and what to put in.
  cin >> initial;

  cout << "Next enter the increment steps of time in hours from 0 to 23\n ";
  cin >> increment;

  cout << "Now the final time from 0 to 23 hrs \n";
  cin >> final_time;

  cout << "\n\n Drone Altitude Table\n";
  cout << "Time(hrs)      Altitude(meters)\n";
  cout << "____________________________\n";

  cout.setf(ios::fixed);
  cout << setprecision(5);

  for (int count = 0; count <= loops; ++count)
    loops = (int) ((final_time - initial) / increment); //Declaring loop variable

  {
    time = initial + count * increment;
    altitude = -0.12 * pow(time, 4) + 12.1 * pow(time, 3) - 360 * pow(time, 2) + 3910 * time; // Our equation we wiil be working with
    cout << setw(6) << time << setw(6) << altitude << endl; // For more accurate results
    if (altitude > max_altitude) {
      altitude = max_altitude;
      max_time = time;
    }

    cout << "\nThe maximum altitude of the drone was " << setw(8) << max_altitude << "meters \n" << endl;
    cout << "and it reached it's maximum altitude at " << setw(6) << max_time << "hrs \n" << endl;
  }

  return 0;
}

Line 32 onwards, despite the use of braces, is NOT part of your for loop on line 29.
Topic archived. No new replies allowed.