Code error

Hi..can some1 correct my code?what did i mistaks here?i didn't get...?please tell.. :(
code(1)..
#include <iostream.h>

main()
{
int number;
int digit;
cout<< "please Enter a 4 digit integer:";
cin>>number;
digit=number% 10;
cout<< "the digit is:"<< digit << '\n';
number=number/10;
digit=number%10;
cout<<"the digit is:"<< digit <<'\n';
number=numbre/10;
digit=number%10;
cout<<"the digit is:"<< digit <<'\n';
number=number/10;
digit=number%10;
cout<<"the digit is:"<< digit;

}
code(2)...
#include <iostream.h>
main()
{
int age1,age2,age3,age4,age5,age6,age7,age8,age9,age10;
int totalAge;
int averageAge;
cout <<"please enter the age of student1:" ;
cin >>age1;
cout <<"please enter the age of student2:" ;
cin >>age2;
cout <<"please enter the age of student3:" ;
cin >>age3;
cout <<"please enter the age of student4:" ;
cin >>age4;
cout <<"please enter the age of student5:" ;
cin >>age5;
cout <<"please enter the age of student6:" ;
cin >>age6;
cout <<"please enter the age of student7:" ;
cin >>age7;
cout <<"please enter the age of student8:" ;
cin >>age8;
cout <<"please enter the age of student9:" ;
cin >>age9;
cout <<"please enter the age of student10:" ;
cin >>age10;

Totalage = age1+ age2+ age3+ age4+ age5+ age6+ age6+ age7+ age8+ age9+ age10;
AverageAge = Totalage /10;
cout <<"the Average Age of the class is:"
<< AverageAge;
}
Regardz.
They both should work. Some problems : main should be int, and therefore should return something (0 preferably). Also, you should probably be using loops and arrays. For example
1
2
3
4
5
6
7
8
9
10
11
digit=number% 10;
cout<< "the digit is:"<< digit << '\n';
number=number/10;
digit=number%10;
cout<<"the digit is:"<< digit <<'\n';
number=numbre/10;
digit=number%10;
cout<<"the digit is:"<< digit <<'\n';
number=number/10;
digit=number%10;
cout<<"the digit is:"<< digit;
could become
1
2
3
4
5
for(int i = 0; i < 4; i++){
    digit = number%10;
    cout << "digit"<<i+1<<" is : " << digit << '\n';
    number /= 10;
}
You could save even more lines in the second example.
Hamsterman,i hv still face this problem,i m new in C++,i wrote it,but error occured.i think,...may be i could not understand it..!... :(
You forgot std namespace (either using namespace std; or add std:: before every cin and cout)
What did the error say?
Last edited on
check it please.. :(

using namespace std::
#include <iostream.h>
#include <conio.h>
main()
{
int number;
int digit;

cout<< "please Enter a 4 digit integer:";
using namespace std::
cin>>number;
digit=number% 10;
using namespace std::
cout<< "the digit is:"<< digit << '\n';
number=number/10;
digit=number%10;
using namespace std::
cout<<"the digit is:"<< digit <<'\n';
number=numbre/10;
digit=number%10;
using namespace std::
cout<<"the digit is:"<< digit <<'\n';
number=number/10;
digit=number%10;
using namespace std::
cout<<"the digit is:"<< digit;
getch();
}
You must write using namespace std; after you include iostream.
ohhh ok thanks...
Topic archived. No new replies allowed.