need help with cin.getnum?

how do i get.line() for integers ?
sorry iam very new with c++ and with this website.
if my quastin is idiotic delete it.
tnx for helpers.
//code
include <iostream>
using namespace std;
void Div(int* num);
void Prime( int* num );
void Sum(int* num);
void main(){
int *num= new int[4]; //like 1000??
int a;
cout << "1" << endl;
cout << " 2" << endl;
cout << " 3" << endl;
cout << "To exit press 0" << endl;
cin >> a;
cin.ignore();
switch (a){
case 0:
cout << "Good bye" << endl;
exit(0);
break;
case 1:
cout << "Enter your number:" << endl;
cin >> num; // cin.getline()? but for int number if it was a char i would do like cin.getline(str,4)? right?
Div(num);
break;
case2:
cout << "Enter your Number" << endl;
Prime(num);
break;
case 3:
cout << "Enter your Number" << endl;
Sum(num);
break;
}
Next time, use code formatting([.code] tag, without the dot).

As for the question: please, read once again the chapter about integers, pointers and I/O. int* is a pointer to an integer, and you want to get integer. num should be an int, not int*. Moreover, int[4] is an array of 4 integers, instead of 4-wide integer.

Also, void main() isn't C++. You should use int main() (with optional arguments, if you want to use them). Main must return an int.
any idea where is my problem in this code?
[code]

#include <iostream>
using namespace std;
int num;
void Div(int num);
void Sum(int num);

void main(){
int a;
cout << "Enter your option:" << endl;
cout << "for how many deviders press 1" << endl;
cout << "for sum of number press 2 " << endl;
cout << "To exit press 0" << endl;
cin >> a;
cin.ignore();
switch (a){
case 0:
cout << "Good bye" << endl;
exit(0);
break;
case 1:
cout << "Enter your number:" << endl;
cin >> num;
Div(num);
break;
case 2:
cout << "Enter your Number" << endl;
cin >> num;
Sum(num);
break;

}
system("pause");

}
void Div(int num){
int counter = 0;
for (int i = 2; i < num; i++){
if (num % i == 0){
cout << i << endl;
counter++;
}

}
cout << "The amount of dividers is" << counter << endl;
}
void Sum(int num){
int h = 0;
while (num > 10){
h += num % 10;
num = num / 10;


}
if (num < 10){
h += num;
}
cout << "The sum of Number is:" << h << endl;


}
Last edited on
Topic archived. No new replies allowed.