B
bballmitch
I have the following code
#include <cstdlib>
#include <iostream>
#include <fstream>
int score_one=2345, score_two=1800, score_three=1500, score_four=1300,
score_five=1100;
int score_six=1000, score_seven=900, score_eight=860, score_nine=700,
score_ten=600;
using namespace std;
ifstream* openFile(istream& input)
{
for(;
{
ifstream* pFileStream = new ifstream("HighScores2.txt");
return pFileStream;
}
}
int main(int argc, char *argv[])
{
cout<<"Please enter an integer.\n";
int score;
cin>>score;
cout<<"\n";
ofstream my("HighScores2.txt");
if(score>=score_one)
{
score_one=score;
}
my<<"1. "<<score_one<<endl;
my<<"2. "<<score_two<<endl;
my<<"3. "<<score_three<<endl;
my<<"4. "<<score_four<<endl;
my<<"5. "<<score_five<<endl;
my<<"6. "<<score_six<<endl;
my<<"7. "<<score_seven<<endl;
my<<"8. "<<score_eight<<endl;
my<<"9. "<<score_nine<<endl;
my<<"10. "<<score_ten<<endl;
ifstream* pFileStream = openFile(cin);
char buffer[80];
while(!pFileStream->eof() && pFileStream->good())
{
pFileStream->read(buffer, 80);
int noBytes = pFileStream->gcount();
for(int i=0; i<noBytes;i++)
{
cout<< buffer;
}
}
int k=buffer[0];
cout<<"\n\n"<<k<<" is the best number in the world.\n";
system("PAUSE");
return EXIT_SUCCESS;
}
but then when i cout the integer k, it ALWAYS has an output of 46.
unless its above 2000, in which case its something else. but i can't
figure out where 46 is coming from. i know like there is no practical
reason for why im doing this, but there is. my questions are these...
1. where is the 46 coming from?
2. how do i figure out how many numbers/characters are in a line in a
file?
3. lets say that my file has the following in it...
1. 2000
2. 1800
3. 1500
how do i make it so that if a number is greater than 2000 then it
becomes 1, and 2000 becomes two and so on and so forth? im able to do
that once, but because every time im declaring the variables, it always
restarts so that 1 is 2000 2 is 1800 etc.
#include <cstdlib>
#include <iostream>
#include <fstream>
int score_one=2345, score_two=1800, score_three=1500, score_four=1300,
score_five=1100;
int score_six=1000, score_seven=900, score_eight=860, score_nine=700,
score_ten=600;
using namespace std;
ifstream* openFile(istream& input)
{
for(;
{
ifstream* pFileStream = new ifstream("HighScores2.txt");
return pFileStream;
}
}
int main(int argc, char *argv[])
{
cout<<"Please enter an integer.\n";
int score;
cin>>score;
cout<<"\n";
ofstream my("HighScores2.txt");
if(score>=score_one)
{
score_one=score;
}
my<<"1. "<<score_one<<endl;
my<<"2. "<<score_two<<endl;
my<<"3. "<<score_three<<endl;
my<<"4. "<<score_four<<endl;
my<<"5. "<<score_five<<endl;
my<<"6. "<<score_six<<endl;
my<<"7. "<<score_seven<<endl;
my<<"8. "<<score_eight<<endl;
my<<"9. "<<score_nine<<endl;
my<<"10. "<<score_ten<<endl;
ifstream* pFileStream = openFile(cin);
char buffer[80];
while(!pFileStream->eof() && pFileStream->good())
{
pFileStream->read(buffer, 80);
int noBytes = pFileStream->gcount();
for(int i=0; i<noBytes;i++)
{
cout<< buffer;
}
}
int k=buffer[0];
cout<<"\n\n"<<k<<" is the best number in the world.\n";
system("PAUSE");
return EXIT_SUCCESS;
}
but then when i cout the integer k, it ALWAYS has an output of 46.
unless its above 2000, in which case its something else. but i can't
figure out where 46 is coming from. i know like there is no practical
reason for why im doing this, but there is. my questions are these...
1. where is the 46 coming from?
2. how do i figure out how many numbers/characters are in a line in a
file?
3. lets say that my file has the following in it...
1. 2000
2. 1800
3. 1500
how do i make it so that if a number is greater than 2000 then it
becomes 1, and 2000 becomes two and so on and so forth? im able to do
that once, but because every time im declaring the variables, it always
restarts so that 1 is 2000 2 is 1800 etc.