You are here:

C++/please help me out


Please can u help me out
i am trying to read (the numbers) from the text file.
and it is working perfectly
after that i am tryng the calculate the total sum  what ever is in txt file , it is not working
can u help me out to calculate the total ammount form text file

#include <string>
#include <conio.h>
#include <stdlib.h>
#include <iostream>
#include <cstdlib>
#include <string>

int twohundert;
int hundert;
int fifty;
int twenty;
int ten;
int five;
int two;
int one;
int sum;
int ammount50[10];

void ammount()
  cout <<"\n\n\n\n\t\tQuantity of " <<(char)156<<"2 Coin's";
  cin >>twohundert;
  cout <<"\n\t\tQuantity of " <<(char)156<<"1 Coin's";
  cin>> hundert;
  cout <<"\n\t\tQuantity of 50p Coin's";
  cin >>fifty;
  cout <<"\n\t\tQuantity of 20p Coin's";
  cin>>  twenty;
  cout <<"\n\t\tQuantity of 10p Coin's";
  cin >> ten;
  cout <<"\n\t\tQuantity of 5p Coin's";
  cin >> five;
  cout <<"\n\t\tQuantity of 2p Coin's";
  cin >> two;
  cout <<"\n\t\tQuantity of 1p Coin's";
  cin >>one;

  ofstream myfile; ("twohundert.txt", ios::app);
    myfile <<twohundert << endl;
   ofstream myfile2; ("hundert.txt", ios::app);
    myfile2 <<hundert << endl;

   ofstream myfile3; ("fifty.txt", ios::app);
    myfile3 <<fifty << endl;

   ofstream myfile4; ("twenty.txt", ios::app);
    myfile4 <<twenty << endl;

   ofstream myfile5; ("ten.txt", ios::app);
    myfile5 <<ten << endl;

   ofstream myfile6; ("five.txt", ios::app);
    myfile6 <<five << endl;

   ofstream myfile7; ("two.txt", ios::app);
    myfile7 <<two << endl;

   ofstream myfile8; ("one.txt", ios::app);
    myfile8 <<one << endl;
  char number[10];
   int *readnumbers = 0;
  string line;
  ifstream myfile9("twohundert.txt",ios::in);
      readnumbers = new int[10];
      {int i = 0;
         cout<<number  << " ";


For basics of file input, see:

Find the sum of all integers in a file:
       std::ifstream file( "filename.txt" ) ; // open the file for input
       int sum = 0 ;
       int number ;
       while( file >> number ) // while another number can be read
         sum += number ; // add the number just read to the sum  


All Answers

Answers by Expert:

Ask Experts




my primary areas of interest are generic and template metaprogramming, STL, algorithms, design patterns and c++11. i would not answer questions about gui and web programming.


about 15 years or so

post graduate engineer

©2016 All rights reserved.