| View previous topic :: View next topic |
| Author |
Message |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sat Jul 21, 2007 8:57 pm Post subject: [Help C++] Inserting a Loop into a Text File |
|
|
well, i cant seem to take the loop information i get and stick it in the .txt
im using fstream I/O to write the file (ofstream)
this is CLR btw
this is the code snippet of the I/O im using
| Code: | ofstream myFile("specs.txt", ios::app);
if (myFile.is_open())
{
myFile << "Starting Sum: " << ssum << "\nInterest: " << irst << "\n\n\n";
myFile << "Day: " << ++day << "\nMoney: $" << ssum + (irst * day) << "\n\n";
myFile.close();
}
else { cout << "Unable to open Text Document"; } |
now the | Code: | | "Day: " << ++day << "\nMoney: $" << ssum + (irst * day) << "\n\n"; |
is obviously the loop, but i cant seem to get the loop into the txt document.
all together the loop is:
| Code: | while (day > 365)
{
cout << "Day: " << ++day << "\nMoney: $" << ssum + (irst * day) << "\n\n";
} |
helps appreciated...
the program asks u for your starting sum, then the daily interest, then the loop is supposed to show everyday's money. but obviously the CLR box isnt big enough. so a .txt document is my only choice
Edit: oh yea, before i forget, is there a way to increase by percent in C++, ive searched around but have found nothing.
% = modules (remainder) so theres nothing else i can think of accept for maybe deviding the number by 100 then multiplying by the percent
_________________
|
|
| Back to top |
|
 |
Robotex Master Cheater
Reputation: 0
Joined: 05 Sep 2006 Posts: 378 Location: The pizza country!
|
Posted: Sat Jul 21, 2007 11:00 pm Post subject: |
|
|
that works to me
| Code: |
#include <windows.h>
#include <iostream>
#include <fstream>
using std::cin;
using std::cout;
using std::ofstream;
int main()
{
int day = 0;
int ssum;
int irst;
ofstream myFile("specs.txt", std::ios::app);
cin >> ssum >> irst;
if (myFile.is_open())
{
myFile << "Starting Sum: " << ssum << "\nInterest: " << irst << "\n\n\n";
while (day < 365)
{
myFile << "Day: " << ++day << "\nMoney: $" << ssum + (irst * day) << "\n\n";
}
myFile.close();
}
else { cout << "Unable to open Text Document"; }
return 0;
} |
_________________
ASM/C++ Coder
Project Speranza lead developer |
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sun Jul 22, 2007 7:52 am Post subject: |
|
|
it sent everysingle (365) line of the loop into your text file?
_________________
|
|
| Back to top |
|
 |
Robotex Master Cheater
Reputation: 0
Joined: 05 Sep 2006 Posts: 378 Location: The pizza country!
|
Posted: Sun Jul 22, 2007 9:37 pm Post subject: |
|
|
yes, btw i think your problem was
while (day > 365)
wich is supposed to be
while (day < 365)
?
_________________
ASM/C++ Coder
Project Speranza lead developer |
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Mon Jul 23, 2007 6:43 pm Post subject: |
|
|
well i feel like an idiot.... -.-
yea, i figured that out last night, i just never thot to try and make it go in the text file.
well. lock this plz.
_________________
|
|
| Back to top |
|
 |
|