i am stuck on how to fix this code, it was my first real attempt at trying to make a program without some sample code. and i got stuck on the darn compiler lol
the error was untitled.cxx:7:1: error: expected initializer before ‘int’
#include <iostream>
usingnamespace std;
void exponent()
int main()
{
int base;
int answer;
cin>>base;
if(base<=0)
{
cout<<"sorry that was an invalid input, please input a positive number..."<<endl;
}
return 0;
}
void exponent(int base, int answer)
{
cout<<"I am going to square the number you are going to input!"
cout<<" "<<endl;
cout<<"What is your base number?"<<endl;
cin>>base>>endl;
cout<<"Are you sure you want "<<base<<" for a base number?"<<endl;
cout<<" "<<endl;
cout<<"Just so you know, you typed "<<base<<" for a base number."<<endl;
base * base = answer;
cout<<"Your input to the second power is "<<answer<<" isn't it!!!"<<endl;
}
// ...
usingnamespace std;
void exponent() ; // the terminator ie. ; was missing here
int main() // this is line 7 - 7:1: error: expected initializer before ‘int’
// 7:1 indicates error at line 7 col 1
{
// ..
An initializer is something that specifies an initial value for the identifier being defined.
In int a_number = 99 * 6 ;= 99 * 6 is the initializer.
> do i need to put anything in the parenthesis such as...
Yes.
1 2 3 4 5 6 7 8 9 10 11 12
void exponent(int base, int answer) ; // declaration
int main()
{
// ....
}
void exponent(int base, int answer) // no ; here - the definition follows
{ // definition
cout<<"I am going to square the number you are going to input!"
// ... other statements
}
thank you very much for the definition of initializer, it makes so much sense lol, but i don't expect you guys to compile the code or anything but if i but a ; after
I can just make it int instead of void and call it like in that example. The original intention of the program was to make it without sample code but i think i understand what i need and hey, i learned something...
why can't the compiler just say take away the >>endl; and if you want to use endl; you gotta use it when you're "couting" and not "cinning?" lol thanks a ton!