-
while-loop woes...
I'm trying to get this while loop to work but I keep getting errors (as usual)
Here's what I have:
Code:
#include <iostream>
using namespace std;
void instructions ();
void calculations ();
int header;
int table;
int main ()
{
instructions ();
calculations ();
header;
table;
return 0;
}
void calculations ()
int header()
{
cout << "TABLE OF NUMBERS AND THEIR SQUARES" << endl;
cout << " Number Square " << endl;
cout << " ------ ------ " << endl;
return 0;
}
int table()
{
int num, square;
num = 0;
while (num <= 5)
{
square = num * num;
if (num < 5)
cout << " " << num << " " << square << endl;
else
cout << " " << num << " " << square << endl;
num = num + 1;
}
return 0;
}
It's supposed to display a table of intergers (1 thru 5) and their squares.
Thanks for your help.
-
if you want the program to display 1-5 why do you initialize num to zero?
anyhow you are missing an ; after void calculations.
also, header and table are functions, so why are you declaring them as variables up top?
replace with
int header(); and int table();
Also, you are calling calculations() and instructions from iside main yet they have not been defined anywhere. You do need a function definition even if it is empty. When you call header and table you also forgot the (). DID YOU DO ANY DEBUGGING HERE?!
what compiler are you using...
One more thing...if you want a function to display something and not do any calculation make it void....make your calculation functions of the return type.
axon
-
the brackets.. watch your opening and closing brackets for calculations(). You missed something there dude.
-
try this...
Code:
#include <iostream>
using namespace std;
void header();
void table();
int main ()
{
header();
table();
return 0;
}
void header()
{
cout << "TABLE OF NUMBERS AND THEIR SQUARES" << endl;
cout << " Number Square " << endl;
cout << " ------ ------ " << endl;
}
void table()
{
int num, square;
num = 1;
while (num <= 5)
{
square = num * num;
cout << " " << num << " " << square << endl;
num = num + 1;
}
}
-
Thank you, Pratip
That's exactly how I needed it to display.
-
Pratip, could you do my homework? please
-
Axon, why not... provided you have to do mine :-) hahaha...