Tak for det.. nu fik jeg det "built" og compile med de her resultater:
1>------ Build started: Project: Full LynLotto opgave, Configuration: Debug Win32 ------
1>Compiling...
1>Skipping... (no relevant changes detected)
1>Full LynLotto opgave.cpp
1>Build log was saved at "file://c:\Finnur\Elektrikingenior IOT\Reeksam i E-DTP\Full LynLotto opgave\Full LynLotto opgave\Debug\BuildLog.htm"
1>Full LynLotto opgave - 0 error(s), 0 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
Har lavet de ændringer som du snakkeder om
også i int main, har jeg gjort det her
//srand((unsigned)&c);
Men så hvis jeg vil så debug, så kommer bare en
kæmpe fejl.
Debug Assertion Failed!
Program:...
File:c:\program files\microsoft visual studio8\vc\include\list
Line:262
Expression: list iterator not decrementable
For information on how your program can cause an assertion failure, see the visualC++ doocumentation on asserts.
(press retry to debug the application)
"Abort" "Retry" "Ignore"
Hele Koden:
#include "stdafx.h"
#include <iostream>
#include <string>
#include <list>
#include <cstdlib>
#include <algorithm> //find()
#include <sstream> //ostringstream
#include <iomanip> //setfill() setw();
using namespace std;
const int NUMBER_COUNT = 7;
const int NUMBER_MAX = 36;
const int NUMBER_MIN = 1;
const int ROWS_COUNT = 10;
//*****************************************************************************
// Function that returns random number between NUMBER_MIN and NUMBER_MAX
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
int Bold()
{
return (rand() % (NUMBER_MAX - NUMBER_MIN + 1) + NUMBER_MIN);
}
//*****************************************************************************
// Returns random number between NUMBER_MIN and NUMBER_MAX
// Will always return a different random number until this function is call
// whith new_draw=true.
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
int Kugle(bool new_draw = false)
{
static list<int> drawn_lst; //list to keep values that have been draw.
if (new_draw) // Clean and return.
{
drawn_lst.clear(); //New deal, clears the list
}
else if (drawn_lst.size() >= (unsigned int)NUMBER_MAX)
//else if (drawn_lst.size() >= NUMBER_MAX)
{
cout << "*** No more balls - clear list ***" << endl;
}
else
{
int ball = 0;
do
{
ball = Bold();
}
while (drawn_lst.end() != find(drawn_lst.begin(), drawn_lst.end(), ball));
drawn_lst.push_back(ball);
}
return drawn_lst.back();
}
//*****************************************************************************
// Inserts random numbers in the list lst.
// Count of random numbers are NUMBER_COUNT.
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void Saturday(list<int> &lst)
{
for (int i = 0;NUMBER_COUNT > i;i++)
{
lst.push_back(Kugle());
}
}
//*****************************************************************************
// Inserts random numbers in list and then insert list in list of list(row_lst).
// cont of random numbers are NUMBER_COUNT
// cont of list in list are ROWS_COUNT
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void Lynlotto(list< list<int> > &row_lst) //void fyrir int
{
for(int i=0; ROWS_COUNT>i;i++)
{
list<int> lst;
Kugle(true); //Clears the already drawn list of numbers.
Saturday(lst); //add random numbers to lst
row_lst.push_back(lst);
}
}
//*****************************************************************************
// converts list of int to string e.g. [2] [23] [8] ... etc.
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
std::string listToString(list<int> &lst)
{
std::ostringstream o;
list<int>::iterator it;
for ( it = lst.begin() ; it != lst.end(); it++ )
{
o << " [" << setw(2) << setfill(' ') << *it << "]";
}
return o.str();
}
//*****************************************************************************
// The main funtion
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
int main(int c, char **a)
{
//srand((unsigned)&c);
list< list<int> > lynlotto_lst; //This is a list of list of integers
list<int> saturday_lst; //this is a list of integers
int bonus_number; //to keep the bonus number.
Saturday(saturday_lst); //add random numbers to lst
bonus_number = Kugle(); //Draw the bonus number
Kugle(true); //Clear drawn nubmer list.
Lynlotto(lynlotto_lst); //add random numbers to lst x 10
cout << endl << "The lotto numbers are:" << endl << " " << listToString(saturday_lst) << " bonus[" << Kugle() << "]" << endl;
int ln_num = 0;
list< list<int> >::iterator it_lyn_rows;
cout << "The selected numbers are:" << endl;
for ( it_lyn_rows = lynlotto_lst.begin() ; it_lyn_rows != lynlotto_lst.end(); it_lyn_rows++ )
{
ln_num++;
cout << setw(2) << setfill(' ')<< ln_num << ":" <<listToString(*it_lyn_rows) << endl;
}
cout << endl << endl;
return 0;
}
har i nogen idéa hvorfor det kommer,kan det være den udgave af c++ som jeg har,
(Visual c++ 2005 express edition)
Hilsen
Finns
Indlæg senest redigeret d. 01.12.2008 15:17 af Bruger #14423