Lottoprogramm Ausgabe formatieren

07/01/2012 15:14 Explode:)#1
Hey Community,

ich muss derzeit für die Schule ein Lottoprogramm schreiben, es funktioniert alles aber ich habe noch etwas Probleme mit der Ausgabe.


Hier der Quellcode:

Code:
//Headerdateien
#include <iostream>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <windows.h>
using namespace std;

//************************************************** ************************************************
//Prototypen
void tippen(int*);
void ausgeben(int*);
void ziehen(int*);
void sortieren(int*);
void auswerten(int*,int*);
bool doppelt(int*,int);
void gotoxy(int x, int y);

//************************************************** ************************************************




//************************************************** ************************************************
//Hauptprogramm
int main()
{

//Variablen und Arrays deklarieren
int ar_tipp[6];
int ar_ausgeben[6];
int ar_lotto[6];
char wiederholen;
int zeichen;

system("cls");



//Funktionsaufruf "Tippen"

for(int i=1;i<=8;i++)//Ecke Links oben
{
gotoxy(15,i);//position des Koersers
zeichen= 201;
cout<<zeichen<<"\n";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HA NDLE), 12);
gotoxy(15,1);
cout<<"xxx xxxx xxxxxxxxx xxxxxxxxx xxxx " <<endl;
gotoxy(15,2);
cout<<"xxx xx xx xxxxxxxxx xxxxxxxxx xx xx "<<endl;
gotoxy(15,3);
cout<<"xxx xx xx xx xx xx xx"<<endl;
gotoxy(15,4);
cout<<"xxx xx xx xx xx xx xx"<<endl;
gotoxy(15,5);
cout<<"xxx xx xx xx xx xx xx " <<endl;
gotoxy(15,6);
cout<<"xxx xx xx xx xx xx xx"<<endl;
gotoxy(15,7);
cout<<"xxxxxxx xx xx xx xx xx xx " <<endl;
gotoxy(15,8);
cout<<"xxxxxxx xxxx xx xx xxxx "<<endl;
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HA NDLE), 14);
gotoxy(30,11);
cout<<"Willkommen zum Lottospiel."<<endl;
gotoxy(25,13);
cout<<"Bitte geben sie 6 von 49 Zahlen ein"<<endl;

tippen (ar_tipp);


ziehen (ar_lotto);

auswerten (ar_tipp, ar_lotto);
cout<<"\nMoechten sie nochmal spielen? -J/N"<<endl;
cin>>wiederholen;
if(wiederholen=='j')
{

main();
}



return 0;
}


//************************************************** ************************************************
//Unterprogramme

//Unterprogramm "Tippen" usw.
void tippen(int* ar_tipp)
{





for(int i=0; i<6; i++)
{ gotoxy(2, i+15);

cout<<i+1<<". Tipp: ";
cin>>ar_tipp[i];
if(ar_tipp[i]<1 || ar_tipp[i]>49)
{
gotoxy(5,22);

cout<<"Der gewuenschte Tipp ist nicht gueltig"<<endl;
i--;

}

if(doppelt(ar_tipp,i))
{
gotoxy(5,22);

cout<<"Die Zahl wurde bereits schon eingegeben! Bitte Eingabe wiederholen."<<endl;
i--;

}



}



system("cls");
ausgeben(ar_tipp);



}


//************************************************** ************************************************
//Unterprogramm "Ausgeben" usw.

void ausgeben(int* ar_ausgeben)
{
int temp1;
int zeichen;

for(int i=1;i<=8;i++)//Ecke Links oben
{
gotoxy(15,i);//position des Koersers
zeichen= 201;
cout<<zeichen<<"\n";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HA NDLE), 12);
gotoxy(15,1);
cout<<"xxx xxxx xxxxxxxxx xxxxxxxxx xxxx " <<endl;
gotoxy(15,2);
cout<<"xxx xx xx xxxxxxxxx xxxxxxxxx xx xx "<<endl;
gotoxy(15,3);
cout<<"xxx xx xx xx xx xx xx"<<endl;
gotoxy(15,4);
cout<<"xxx xx xx xx xx xx xx"<<endl;
gotoxy(15,5);
cout<<"xxx xx xx xx xx xx xx " <<endl;
gotoxy(15,6);
cout<<"xxx xx xx xx xx xx xx"<<endl;
gotoxy(15,7);
cout<<"xxxxxxx xx xx xx xx xx xx " <<endl;
gotoxy(15,8);
cout<<"xxxxxxx xxxx xx xx xxxx "<<endl;
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HA NDLE), 14);
gotoxy(30,11);
cout<<"Willkommen zum Lottospiel."<<endl;
gotoxy(25,13);
cout<<"Bitte geben sie 6 von 49 Zahlen ein"<<endl;

cout<<"\nIhr Tipp:"<<endl;

for(int i=0; i<6; i++)
{
for(int j=0; j<6;j++)
{
if(ar_ausgeben[j]>ar_ausgeben[j+1])
{
temp1=ar_ausgeben[j];
ar_ausgeben[j]=ar_ausgeben[j+1];
ar_ausgeben[j+1]=temp1;
}
}
}
for(int k=0; k<6;k++)
{
cout<<k+1<<". Zahl= "<<ar_ausgeben[k]<<"\n"<<endl;
}



}


//************************************************** ************************************************
//Unterprogramm "Ziehen" usw.
void ziehen(int* ar_lotto)
{


srand((unsigned)time(NULL));//Zufallszahlengenerator starten.


for(int i=0;i<6; i++)
{
ar_lotto[i]=rand()%49+1;



if(doppelt(ar_lotto,i))
{
i--;
}
}
sortieren(ar_lotto);

}


//************************************************** ************************************************
//Unterprogramm "Sortieren" usw.
void sortieren(int* ar_lotto)
{

int temp;
int zeichen;
for(int l=0; l<1; l++)
{




cout<<"Lottozahlen:";
{




for(int i=0; i<6; i++)
{
for(int j=0; j<6;j++)
{
if(ar_lotto[j]>ar_lotto[j+1])
{
temp=ar_lotto[j];
ar_lotto[j]=ar_lotto[j+1];
ar_lotto[j+1]=temp;
}
}
}
}



for(int k=0; k<6;k++)

{


cout<<"\n"<<k+1<<". Zahl= "<<ar_lotto[k]<<endl;


}


}
}



//************************************************** ************************************************
//Unterprogramm "Auswerten" usw.
void auswerten(int* ar_tipp,int* ar_lotto)
{

int k=0;
for(int i=0; i<6; i++)
{

for(int j=0; j<6; j++)
{
if(ar_tipp[i]==ar_lotto[j])
{

k++;
}
}
}


cout<<"\n Sie haben "<<k<<" richtige Zahlen";
}



//************************************************** ************************************************
//Unterprogramm "Doppelt" usw.
bool doppelt(int* ar_zahlen ,int i)
{
if(i>0)
{
for(int j=0; j<=i-1; j++)
{
if(ar_zahlen[j]==ar_zahlen[i])
{
return(true);
}
}

}
return(false);

}
void gotoxy(int xpos, int ypos)
{
COORD scrn;
HANDLE hOuput = GetStdHandle(STD_OUTPUT_HANDLE);
scrn.X = xpos; scrn.Y = ypos;
SetConsoleCursorPosition(hOuput,scrn);
}



//True oder false

Es geht um diese Stelle:

********************
//Unterprogramm "Sortieren" usw.
void sortieren(int* ar_lotto)
{

int temp;
int zeichen;
for(int l=0; l<1; l++)
{




cout<<"Lottozahlen:";
{




for(int i=0; i<6; i++)
{
for(int j=0; j<6;j++)
{
if(ar_lotto[j]>ar_lotto[j+1])
{
temp=ar_lotto[j];
ar_lotto[j]=ar_lotto[j+1];
ar_lotto[j+1]=temp;
}
}
}
}



for(int k=0; k<6;k++)

{


cout<<"\n"<<k+1<<". Zahl= "<<ar_lotto[k]<<endl;


}


}
}
Ich hätte gern die Lottozahlen Rechts neben den getippten Zahlen. Ich habe mir vorgestellt das dies mit gotoxy(); möglich wäre, jedoch klappt das nicht so wie ich es mir denke. Könnt ihr mir vielleicht helfen?

Mit freundlichen Grüßen

Manu/Explode

#push!"
07/02/2012 12:35 MrSm!th#2
Du kannst in der Konsole nur linear Text ausgeben, du kannst nicht einfach vor und zurückspringen, wie es dir beliebt.
07/02/2012 15:33 Nightblizard#3
Natürlich kann er das!
[Only registered and activated users can see links. Click Here To Register...]

Beispiel:
Code:
COORD coord = { 5, 15 };
auto stdHandle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(stdHandle, coord);
std::cout << "456";
COORD.X = 0;
SetConsoleCursorPosition(stdHandle, coord);
std::cout << "123";
Ausgabe:
123 456


Ob und wie das auf Linux funktioniert kann ich dir jedoch nicht sagen.
07/02/2012 15:50 MrSm!th#4
Ok, war mir neu oO
Habs halt so in Büchern gelernt, allerdings lehren die ja auch nur den Standard und der stellt sowas nicht bereit, ist ja ne Windows API.