← Discussion

What Is The Problem?

AliJavaheri · 2015-02-25 00:06:09

This is my code and i get wrong answer in the judge system but this code isn't have any problem in my compiler
 Plz help me . Tnx

         int main(){ 
         string str; ifstream infile; ofstream output; infile.open("Input.txt"); output.open("Output.txt");
         while (infile >> str && str != "0"){
             int sum = 0; for (int i = 0; i < str.length(); i++) { sum += str[i] - '0'; }
             if (sum >= 10){ sum = (sum % 10) + (sum / 10);
             } if (sum < 10){ output << sum << endl; }
             } 
         infile.close(); output.close(); return 0; }

AMiR · 2015-02-25 03:14:35

You shouldn't use files to read/write input/output.

You have to use STDIN and STDOUT. cin and cout in c++.

Look here for examples: https://sharecode.io/discussion/problemset/topic/175

AliJavaheri · 2015-02-25 18:31:22

Tnx you so much amir . problem solved

pages:
  • 1