I have to solve problem using c++, and can't really come up with solution.
The condition is. In a skyscraper there are a lot of offices, on every office door there must be put plate with its number from 1 to the number of the last office. The plate can only contain one digit, so if office number contains two digits there must be two plates. How many plates total will be needed for all office doors.
The text file is duom.txt. with the only value of "16". Means theres 16 offices.
This is what I managed to come up with:
# include <iostream>
# include <cmath>
# include <iomanip>
# include <fstream>
using namespace std;
const char CDfv [] = ("duom.txt");
const char CRfv [] = ("rez.txt");
int main()
{
int n;
int m;
int o;
int z;
ifstream fd (CDfv);
ofstream fr (CRfv);
fd>>n;
for (int i=1;i<10;i++) {
m=n+1;
for (int j=1;j>=10;j++) {
o=n+2;
}
}
z=m+o;
fr<<z<<" ";
}
fd.close();
fr.close();
return 0;
}
I know its not correct, so could someone please help me with this. Also would be very glad if somebody tried compiling it, because my codeblocks refuses to work with compiler even if I installed it seperately manually. :/ but thats another problem.
-----
Seems like solution has been found, thanks to everyone who helped me.
# include <iostream>
# include <cmath>
# include <iomanip>
# include <fstream>
using namespace std;
const char CDfv [] = ("duom.txt");
const char CRfv [] = ("rez.txt");
int main()
{
int limit = 10;
int up = 1;
int viso = 0;
ifstream fd (CDfv);
ofstream fr (CRfv);
fd>>n;
for ( int i = 1; i<=n ;++i ){
if (i==limit){
limit*=10;
up+=1;
}
viso += up;
}
fr<<viso<<" ";
fd.close();
fr.close();
return 0;
}
this should work as non text file variant works like charm, here: http://ideone.com/xoFQwn