Jan 3, 2020 at 3:00am Jan 3, 2020 at 3:00am UTC
what am i doing wrong here what does the program needs
#include<iostream>
#include<cstdlib>
#include<cstdio>
using namespace std ;
int main()
{
int number; int digit ;
}
// take input from user
{
cout<<"enter a 4 digit int number:" ;
cin >>number;
digit=number%10 ;
cout<<" the digits are:";
cout<<digit<<",";
number=number/10;
digit=number%10;
cout<<digit<<",";
number=number/10;
digit=number%10;
cout<<digit<<",";
number=number/10;
digit=number%10
cout<<digit;
}
[/code]
Jan 3, 2020 at 9:09am Jan 3, 2020 at 9:09am UTC
Intuitive indentation and exact error messages.
1 2 3 4 5 6 7 8 9 10
#include<iostream>
int main()
{
int number; int digit ;
} // <- the main() ends here
{ // <- Is this the offending '{' ?
std::cout << "enter a 4 digit int number:" ;
}
The compiler does tell the line, where it sees a syntax error. That is useful information, both for you and us.
[Edit]
A compiler says (about my code):
In function 'int main()':
5:9: warning: unused variable 'number' [-Wunused-variable]
5:21: warning: unused variable 'digit' [-Wunused-variable]
At global scope:
8:1: error: expected unqualified-id before '{' token
"
At global scope ": lines 8-10 are not inside any function. What did we forget or misplace?
1 2 3 4 5 6 7 8 9 10 11
#include<iostream>
int main()
{
int number;
int digit ;
{
std::cout << "enter a 4 digit int number:" ;
}
} // <- the main() ends here
Last edited on Jan 3, 2020 at 10:34am Jan 3, 2020 at 10:34am UTC