# help!!!

Page 1 of 1

## 1 Replies - 1175 Views - Last Post: 17 May 2001 - 02:18 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=2470&amp;s=efd96a71be8a94c10eb77d8cb72e8388&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 miaka284

Reputation: 0
• Posts: 530
• Joined: 10-May 01

# help!!!

Posted 17 May 2001 - 01:04 PM

okay, my problems is that my infile refused to read my numbers. I had 8,12,16 typed in, in my file. It only read the first number and the rest it gives me zeros and I don't know why.
```void factorial()//asks the user to enter a positive number
{
long int input;//declares input local
infile.open("Factofile.txt", ios::in);
cout<<"Please enter a positive number.
";
infile>>input;
if(input==0)//if statement, for if input is 0
{//it doesn't calculate the number 0
cout<<"By definition, the factorial of 0 is 1.
";}
if(input>0)//if input is bigger than zero then it goes to the next function
{
fact(input);
}if(input<0)//if input is smaller than zero then it kicks out
{
cout<<"You can't calculate factorials with a negative number.
";
factorial();
}
}
long int fact(long int input1)//here is the function that calculates factorial
{
for(long int a = input1-1; a>1; a--)//for loop for doing the number again
{//until the number is equal to one
input1 *= a;
}
info();//calls the function that
infile.close(); //closes the infile//asks the user if they want to play againreturn input1;}

```

Is This A Good Question/Topic? 0

## Replies To: help!!!

### #2 Null and Void

Reputation: 1
• Posts: 204
• Joined: 29-April 01

## Re: help!!!

Posted 17 May 2001 - 02:18 PM

Assuming that your code is correct in most ways (I didn't read it) you can get around this by using spaces or endlines in the file instead of commas.

Or, this is how I'd open, and read two numbers from a file, each being seperated by a comma (With C ANSI Standard I/O). This probably isn't applicable to your code, but it may give you a hint or something:
[code]
#include <stdio.h>

// ...

int a, b;
FILE *fp = fopen("somefile.txt","rt"); // Open the file
if(fp!=NULL) { // If we opened it
// Read an integer, ignore a character (the comma), and read another integer
fscanf(fp,"%d%*c%d",&a,&b);
fclose(fp); // Close it
}