file - c++ error c2373 redefinition different type modifiers -


when run program, error.

c++ error c2373 'readbalance' redefinition different type modifiers

i want read in file write.

// readandwrite.cpp : defines entry point console application. //  #include "stdafx.h" #include <iostream> #include <fstream>  using namespace std;  double readbalance; double balance;  int main () {     double readbalance();     double balance = 0;     ifstream readfile;     readfile.open("renatofile.txt");     char output [100];      if (readfile.is_open())     {          while(!readfile.eof())          {              readfile>>output;          }     }     readfile.close();     balance=atof(output);     return balance; }    

can because i'm returning balance?

i'm guessing wanted define readbalance function , call main, this:

#include "stdafx.h" #include <iostream> #include <fstream> #include <cstdlib>       // need atof  using namespace std;  double readbalance();    // function prototype double balance;          // global variable - don't need @  int main () {     cout << readbalance() << endl;    // print balance      return 0; }  double readbalance() {     double balance = 0;               // local variable hides global...     ifstream readfile;     readfile.open("renatofile.txt");     char output [100];      if (readfile.is_open()) {         while(!readfile.eof()) {             readfile>>output;         }     }     readfile.close();     balance=atof(output);     return balance; } 

note you've declared balance both globally , locally , that's not want.

btw, you're missing include needed atof function (cstdlib).


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -