Debug

can someone please help me debug this?


// function counts down from higher number to lower number entered
// e.g., if numbers entered are 4 and 8
// output is: 8 7 6 5 4
#include<iostream.h>
#include<conio.h>

void main()
{
void countDown(double highest, double lowest);
double high, low, temp;
cout<<"Enter a number ";
cin>>high;
cout<<"Enter another number ";
cin>>low;
if(high < low)
temp = high;
high = low;
low = temp;
countDown(high, low);
getch();
}
void countDown()
{
int x;
for(x = highest; x <= lowest; --x)
cout<<x<<" "<<endl;
}
Compare
void countDown(double highest, double lowest);
with
1
2
3
4
void countDown()
{
...
}
still unsure what that means
They are not the same. In order to use countDown(...) change the parameter so that they match.
1
2
3
4
5
6
void countDown(double highest, double lowest)
{
int x;
for(x = highest; x <= lowest; --x)
cout<<x<<" "<<endl;
}

c++ supports overloading of functions.

so this

int sum(int a, int b)
{
return a+b;
}

and this

int sum()
{
cout << "this does not add anything and returns a constant" << endl;
return 1337;
}

are two distinct functions. If you meant sum(1,3) and you called sum() you get the wrong answer.

The compiler things you are trying to do the above, but you don't have both versions of the function so it becomes confused (and you did not want 2 versions of the function, you just don't understand your syntax error).

you need to call countdown(10,2); //or whatever variables or numbers you need in there.

Topic archived. No new replies allowed.