Simple XML label generator

Hello all,
I'm having a slight issue with my code doing what I want it to (story of my life) and was trying to see if anyone had some ideas. I was trying to use a simple for loop to accomplish my goal.

the only issue i'm having is with the part of code that generates timepoints. I'd like to generate each time point based off of (n=#) by having a starting integer and divide it by n and if that variable equals a whole number like 1.0, 2.0 to insert the time points (to be coded later). With my code now, all I get are a bunch of zeros for the variable when printed with std::cout.

//============================================================================
// Name : Hello.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : LABEL XML C++, Ansi-style
//============================================================================

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <sstream>
#include <stdlib.h>

using namespace std;

int main() {

static int n;
string input;
string filename;
int anum;
string stdnum;
static int group = 1.0;

cout << "studynumber: \n";
cin >> filename;
stdnum = filename;
filename += ".txt";

cout << "number of animals=? : ";
cin >> anum;

cout << "n=? : ";
cin >> n;

// group together math of 1/n for group number
//ofstream filemain;
//filemain.open(filename.c_str());

// HEADER LINE
cout << "\n" << endl;
cout << "<?xml version=\"1.0\" \n"
"encoding=\"utf-8\"?>\n"
"<AddressBook\n "
"Version=\"8.0\"/n "
"DefaultPermutation=\"false\"\n "
"Format=\"Native\">\n";
//filemain.close();
//ADDRESS ENTRY

for (int i=1; i <= anum; i++, group++) {
group = group/n;
cout << " <AddressEntry>\n"
" <AddressData>" << stdnum << " Total:_______\n"
"R" << i << "\n"
<< group << " hr Tare:_______</AddressData>"
"<Name>\n"
"<FirstName>" << stdnum << " Total:_______</FirstName>\n"
"<LastName></LastName>\n";
}

//Address book close
cout << "</AddressBook>";

return 0;
}
n and group are integers. When you put group = group/n for the first time, group is 1 (not 1.0 or 1.0f).

If n is > 1 (let's say 5) then you get this:
group = 1 / 5;

because group is an integer, the decimal is dropped, so instead of 0.2, you get 0.

Answer: Make group and n doubles or floats.
one other quick question then. How would I go about getting a file.open(data.txt) to write in new lines on the file. \n works great for on screen, but writing to a txt file just gets interp. to nothing or a space (as I haven't sat there counting spaces). Any ideas on what the correct function/command I could use?
"\n" should work. Just out of curiosity, try "\r\n". I think there are some windows editors that don't recognize just \n as a newline.
Topic archived. No new replies allowed.