Urgent!!! I need help with this C++ homework!!!

MrChips

Joined Oct 2, 2009
30,712
All persons requesting solutions to homework questions must realize that it is counter intuitive and counter productive to ask for URGENT!!! help. I certainly would not give it to you in a hurry.
 

someonesdad

Joined Jul 7, 2009
1,583
When I see "Urgent!!", all it usually means is we're dealing with a lazy student who put his homework off until the last minute. The leads to the sympathy meter are broken, which mean it doesn't even twitch. :p
 

SgtWookie

Joined Jul 17, 2007
22,230
It's truly remarkable the number of students who believe that a lack of planning on their part should constitute an emergency on our part.
 

ajm113

Joined Feb 19, 2011
174
Why just register on a website just to ask people to do your homework? Doesn't your collage have some sort A++ student in C++ that can give you tutoring? Cause really to me, this question sounds like a walk in the park that I could write myself in 10 minutes. :p
 

t06afre

Joined May 11, 2009
5,934
The problem that the OP wanted served on a silver plate. Is a something you can read about in every textbook about C/C++ DoH!
 

t06afre

Joined May 11, 2009
5,934
What? You guys don't just download the codes for everything you do?
Yes that is correct. And you can learn a lot by looking at and/or modify example code and code from others. But to me it seems like the OP just looked for an easy way out of some homework. It had been quite different if the OP at least had shown some coding attempt and asked for help
 

RiJoRI

Joined Aug 15, 2007
536
I kinda wonder if Silvi was in panic mode, or didn't understand the question, or both. I suspect we'll never know...

--Rich
 

PNeil

Joined Oct 27, 2010
11
#include <fstream>

using namespace std;

int main()
{
int num1=0, num2=0, num3=0, sum=0;

ifstream fin("number.in");
ofstream fout("sum.out");

// read in the numbers
fin >> num1 >> num2 >> num3;

sum=num1+num2+num3;

// write results to files
fout << "Sum of the digits is " << num1 << "+" << num2 << "+" << num3 << " = " << sum;

fin.close();
fout.close();

return 0;
}
 

ajm113

Joined Feb 19, 2011
174
I may as well give him the real answer to this... Since PNeil as we all can tell doesn't clearly work. I mean look at it! He doesn't even use cout and use proper error handling! D:


Rich (BB code):
#include <iostream>
#include <string>
#include <sstream>
#include <string.h>
#include <stdio.h>

using namespace std;

int main(int argc, char *argv[])
{
     unsigned short iValue1;
     unsigned short iValue2;
     unsigned short iSum;

     //Welcome the user!
     cout << "Welcome to my program! Please enter a value! ";

     cin >> iValue1;

     cout << "\n\nValue 2:" << endl;

     cin >> iValue2;

    //Thank the user and write to the file.
    //This part is very hard and long.
    iSum = iValue1 + iValue2;

   char* buffer;
   buffer = new char[iSum];

   int counter = 0;
  string fileName = "output_";
  
  //You can change the extension if you like. ;)
  string ext = ".bin";
  
   cout << "Please wait.... Calculating..." << endl;
   for(;;)
   {
     fileName += counter;
     fileName += ext;
      counter++;

      FILE * fp = fopen(fileName.c_str(), "w");
      fileName = "output_";

      if(!fp)
      {
       cout << "ERRROR: A epic fail has happened!" << endl;
       break;
      }

      fwrite (buffer, 1 , iSum , fp);

    fclose(fp);
   }

    cout << "PROGRAM ENDED...." << endl;
//Make sure we clear some memory! :D
delete [] buffer;

   return 0;
}
Now that's the pro way of doing things! Just compile that and drop the executable to your teacher! ;)
 
Last edited:
Top