Gast
2004-03-25, 18:21:17
Hallo ich hab ein problem mit einem programm das eine "Tankstatistik" erstellen soll. ich hab die zeile mit dem fehler gegenzeichnet. die 3 zeilen funktionieren einzeln probleme aber wenn zwei oder alle zeilen ausführen soll gibt es eine fehlermeldung wenn man die Tankstatistik abruft. Kann mir da einer helfen? danke!
#include <iostream.h>
#include <conio.h>
#include <process.h>
#include <stdlib.h>
#include <setjmp.h>
#include <string.h>
int n,s,d;
double normal[11],super[11],diesel[11];
void tank()
{
char wahl[8];
double array[3][3],liter,literpreis;
int i,x,y;
for(y=0;y<3;y++)
{
for(x=0;x<3;x++)
{
array[y][x]=0;
}
}
cout<<"Bitte geben Sie die Kraftstoffart ein (n für Normal, s für Super, \nd für Diesel, X für eine Tankstatistik)\nKraftstoffart: ";
cin>>wahl;
if(strstr("n",wahl))
{
clrscr();
cout<<"Normal\n";
cout<<"Literpreis: "; cin>>literpreis;
cout<<"Litermenge: "; cin>>liter;
normal[n]=liter*literpreis;
normal[0]+=liter;
n++;
}
if(strstr("s",wahl))
{
clrscr();
cout<<"Super\n";
cout<<"Literpreis: "; cin>>literpreis;
cout<<"Litermenge: "; cin>>liter;
super[n]=liter*literpreis;
super[0]+=liter;
s++;
}
if(strstr("d",wahl))
{
clrscr();
cout<<"Diesel\n";
cout<<"Literpreis: "; cin>>literpreis;
cout<<"Litermenge: "; cin>>liter;
diesel[n]=liter*literpreis;
diesel[0]+=liter;
d++;
}
if(strstr("x",wahl))
{
clrscr();
array[0][0]=normal[0];
array[1][0]=super[0];
array[2][0]=diesel[0];
//füllen der Tankstatistik mit Werten aus der Normal Tabelle
for(i=1;i<n;i++)
{
array[0][1]+=normal[i];
}
//Hier liegt der Fehler
//array[0][2]=array[0][1]/array[0][0];
//füllen der Tankstatistik mit Werten aus der Super Tabelle
for(i=1;i<s;i++)
{
array[1][1]+=super[i];
}
//Hier liegt der Fehler
//array[1][2]=array[1][1]/array[1][0];
//füllen der Tankstatistik mit Werten aus der Diesel Tabelle
for(i=1;i<d;i++)
{
array[2][1]+=diesel[i];
}
//Hier liegt der Fehler
//array[2][2]=array[2][1]/array[2][0];
cout<<"\t\tSumme Liter Summe Kaufpreis Durchschn. Preis/Liter\n";
for(y=0;y<3;y++) //Ausgabe Tanktabelle
{
for(x=0;x<3;x++)
{
cout<<"\t\t"<<array[y][x];
}
cout<<endl;
}
gotoxy(1,2);cout<<"Normal";
gotoxy(1,3);cout<<"Super";
gotoxy(1,4);cout<<"Diesel";
}
}
void ende(jmp_buf);
int main()
{
int i;
n=1;
s=1;
d=1;
for(i=0; i<11; i++)
{
normal[i]=0;
super[i]=0;
diesel[i]=0;
}
jmp_buf jumper;
setjmp (jumper);
clrscr();
tank();
ende(jumper);
return 0;
}
void ende(jmp_buf jumper)
{
int input;
anfang:
cout<< "\n\n\n\nMöchten Sie das Programm Neustarten oder Beenden?\n";
input=getch();
if((input==27) || (input==98) || (input==66))
{
_exit(0);
}
else if((input==13) || (input==110) || (input==78))
{
longjmp(jumper, 1);
}
else
{
clrscr();
gotoxy(20,1); cout<< "BITTE WIEDERHOLEN SIE DIE EINGEBE!";
gotoxy(1,5); cout<< "B für Beenden oder N für Neustarten\n";
goto anfang;
}
}
#include <iostream.h>
#include <conio.h>
#include <process.h>
#include <stdlib.h>
#include <setjmp.h>
#include <string.h>
int n,s,d;
double normal[11],super[11],diesel[11];
void tank()
{
char wahl[8];
double array[3][3],liter,literpreis;
int i,x,y;
for(y=0;y<3;y++)
{
for(x=0;x<3;x++)
{
array[y][x]=0;
}
}
cout<<"Bitte geben Sie die Kraftstoffart ein (n für Normal, s für Super, \nd für Diesel, X für eine Tankstatistik)\nKraftstoffart: ";
cin>>wahl;
if(strstr("n",wahl))
{
clrscr();
cout<<"Normal\n";
cout<<"Literpreis: "; cin>>literpreis;
cout<<"Litermenge: "; cin>>liter;
normal[n]=liter*literpreis;
normal[0]+=liter;
n++;
}
if(strstr("s",wahl))
{
clrscr();
cout<<"Super\n";
cout<<"Literpreis: "; cin>>literpreis;
cout<<"Litermenge: "; cin>>liter;
super[n]=liter*literpreis;
super[0]+=liter;
s++;
}
if(strstr("d",wahl))
{
clrscr();
cout<<"Diesel\n";
cout<<"Literpreis: "; cin>>literpreis;
cout<<"Litermenge: "; cin>>liter;
diesel[n]=liter*literpreis;
diesel[0]+=liter;
d++;
}
if(strstr("x",wahl))
{
clrscr();
array[0][0]=normal[0];
array[1][0]=super[0];
array[2][0]=diesel[0];
//füllen der Tankstatistik mit Werten aus der Normal Tabelle
for(i=1;i<n;i++)
{
array[0][1]+=normal[i];
}
//Hier liegt der Fehler
//array[0][2]=array[0][1]/array[0][0];
//füllen der Tankstatistik mit Werten aus der Super Tabelle
for(i=1;i<s;i++)
{
array[1][1]+=super[i];
}
//Hier liegt der Fehler
//array[1][2]=array[1][1]/array[1][0];
//füllen der Tankstatistik mit Werten aus der Diesel Tabelle
for(i=1;i<d;i++)
{
array[2][1]+=diesel[i];
}
//Hier liegt der Fehler
//array[2][2]=array[2][1]/array[2][0];
cout<<"\t\tSumme Liter Summe Kaufpreis Durchschn. Preis/Liter\n";
for(y=0;y<3;y++) //Ausgabe Tanktabelle
{
for(x=0;x<3;x++)
{
cout<<"\t\t"<<array[y][x];
}
cout<<endl;
}
gotoxy(1,2);cout<<"Normal";
gotoxy(1,3);cout<<"Super";
gotoxy(1,4);cout<<"Diesel";
}
}
void ende(jmp_buf);
int main()
{
int i;
n=1;
s=1;
d=1;
for(i=0; i<11; i++)
{
normal[i]=0;
super[i]=0;
diesel[i]=0;
}
jmp_buf jumper;
setjmp (jumper);
clrscr();
tank();
ende(jumper);
return 0;
}
void ende(jmp_buf jumper)
{
int input;
anfang:
cout<< "\n\n\n\nMöchten Sie das Programm Neustarten oder Beenden?\n";
input=getch();
if((input==27) || (input==98) || (input==66))
{
_exit(0);
}
else if((input==13) || (input==110) || (input==78))
{
longjmp(jumper, 1);
}
else
{
clrscr();
gotoxy(20,1); cout<< "BITTE WIEDERHOLEN SIE DIE EINGEBE!";
gotoxy(1,5); cout<< "B für Beenden oder N für Neustarten\n";
goto anfang;
}
}