Announcement

Collapse
No announcement yet.

Mein erstes Programm :D

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mein erstes Programm :D

    Ich hab neulich ein neues Buch bekommen und das heißt: C++ für Spieleprogrammierer.
    Ich bin noch am Anfang und hab schon mein erses Programm geschrieben.
    Eine art Taschenrechner.

    Das ist mein Quelcode:

    ------------------------------------------------------------------------
    // C++ für Programmierer
    // Versin 1.0
    // Taschenrechner
    //
    #include <iostream>

    using namespace std;

    // Hauptprogramm
    //
    int main ()
    {
    // Variablen
    //
    int Zahl1, Zahl2, Zahl3;
    int Gesamtsumme;



    // Eingabe der Werte

    cout << "Ersten Zahl: ";
    cin >> Zahl1;

    cout << "Zweiten Zahl: ";
    cin >> Zahl2;

    // Berechnung und Ausgabe der Gesamtsumme
    Gesamtsumme = Zahl1 + Zahl2;
    cout << "Ergebnis der + Aufgabe : " << Gesamtsumme << endl;

    // Berechnung und Ausgabe der Gesamtsumme
    Gesamtsumme = Zahl1 - Zahl2;
    cout << "Ergebnis der - Aufgabe : " << Gesamtsumme << endl;

    // Berechnung und Ausgabe der Gesamtsumme
    Gesamtsumme = Zahl1 * Zahl2;
    cout << "Ergebnis der * Aufgabe : " << Gesamtsumme << endl;

    // Berechnung und Ausgabe der Gesamtsumme
    Gesamtsumme = Zahl1 / Zahl2;
    cout << "Ergebnis der : Aufgabe : " << Gesamtsumme << endl;

    cout << "Um das Programm zu Beenden druecke eine Billibige Taste und Bestaetige sie\n";

    cout << "Programmiert von Markus Friesen \n\a";

    // Eingabe der Werte
    cout << "Ende: ";
    cin >> Zahl3;


    return 0;
    }

    ------------------------------------------------------------------------

    Und das ist der Download Link:

    http://rapidshare.com/files/13407661...ion_2.rar.html
    Zuletzt editiert von Markiska; 01.08.2008, 19:35.

  • #2
    Mal abgesehen davon, dass der Link nicht funktioniert: WO ist -mit Ausnahme der Orthographie- das Problem ?
    MfG
    Cheat-Sheets for Developers / Programming Quotes

    Comment


    • #3
      ???

      Damit hab ich kein Problem. Ich wollt nu wissen wie ihr/du das für den Anfang findet.
      http://rapidshare.com/files/13407661...ion_2.rar.html
      der Link muss Funktionieren.

      Comment


      • #4
        Erster Link geht nicht, Zweiter schon.

        Das Programm ist hervorragend für denjenigen, der mit 2 Ziffern diese Rechenoperationen mache will. Also schnell das nächste Programm entwickeln
        Christian

        Comment


        • #5
          Haben wir nicht alle mal klein angefangen?
          Hier, das ist eines meiner ersten Programme das ich vor ca. anderhalb Jahren geschrieben habe.
          Kannst ja ein bisschen dran rumspielen.

          Code:
          #include <stdlib.h>
          #include <conio.h>
          #include <iostream.h>
          #include <stdio.h>
          
          int k[2],s[2],u[2]={0.0,0.0},wahl[3];
          
          char n[2][20]={"CPU","CPU"};
          
          void name()
          {
          
          cout<<"Wie viele Spieler: - 1 = Mensch vs. CPU"<<endl;
          cout<<"                   - 2 = Mensch vs. Mensch"<<endl<<endl;
          
          cout<<"Deine Entscheidung: "; cin>>wahl[0];
          
          	while (wahl[0]<1 || wahl[0]>2) { cout<<"Deine Entscheidung: "; cin>>wahl[0]; }
          
          cout<<endl<<"Name des 1. Spielers: "; cin>>n[0];
          
          	if (wahl[0]==2) { cout<<endl<<"Name des 2. Spielers: "; cin>>n[1]; }
          
          clrscr();
          
          cout<<"Minispiele: - 1 = ja"<<endl;
          cout<<"            - 2 = nein"<<endl<<endl;
          
          cout<<"Deine Entscheidung: "; cin>>wahl[1];
          
          	while (wahl[1]<1 || wahl[1]>2) { cout<<"Deine Entscheidung: "; cin>>wahl[1]; }
          
          }
          
          void weiter()
          {
          
          int w;
          
          cout<<"\n\n\nDrücke 1 für weiter: "; cin>>w;
          
          while (w!=1) { cout<<"Drücke 1 für weiter: "; cin>>w; } clrscr();
          
          }
          
          void mini1()
          {
          
          int a,b,z[2];
          
          cout<<"Minispiel Nr.1"<<endl;
          
          a=random(10)+10;
          
          b=random(2)+1;
          
          	if (wahl[0]==1) z[1]=random(10)+1;
          
          	cout<<endl<<"Wer am dichtesten an der geheimen Zahl ist, bekommt einen Extrapunkt."<<endl<<endl;
          
          	cout<<n[0]<<", tippe eine Zahl von 0 bis 10: "; cin>>z[0];
          
          		while (z[0]<0 || z[0]>10) { cout<<n[0]<<", tippe eine Zahl von 0 bis 10: "; cin>>z[0]; }
          
          	if (wahl[0]==2)
          	{
          	cout<<endl<<n[1]<<", tippe eine Zahl von 0 bis 10: "; cin>>z[1];
          
          		while (z[0]<0 || z[0]>10) { cout<<n[1]<<", tippe eine Zahl von 0 bis 10: "; cin>>z[1]; }
          
          	}
          
          	else cout<<endl<<"Getippte Zahl von CPU: "<<z[1];
          
          	if (b==2) a*=-1;
          
          	cout<<endl<<endl<<"Die Geheimzahl war: "<<a;
          
          		if (z[0]==z[1]) cout<<endl<<endl<<"Keiner bekommt einen Zusatzpunkt.";
          
          		else
                          {
          
          			if (b==1)
          			{
          				if (z[0]>z[1]) { cout<<endl<<endl<<n[0]<<" bekommt einen Zusatzpunkt."; k[0]++; }
          
          				else { cout<<endl<<endl<<n[1]<<" bekommt einen Zusatzpunkt."; k[1]++; }
          		}
          
          		if (b==2)
          		{
          			if (z[0]<z[1]) { cout<<endl<<endl<<n[0]<<" bekommt einen Zusatzpunkt."; k[0]++; }
          
          			else { cout<<endl<<endl<<n[1]<<" bekommt einen Zusatzpunkt."; k[1]++; }
          
          		}
          
          	}
          
          weiter();
          
          }
          
          void mini2()
          {
          
          int a,b;
          
          cout<<"Minispiel Nr.2"<<endl<<endl;
          cout<<"Der Zufall entscheidet."<<endl<<endl;
          cout<<"Wer die höchste Zahl bekommt, gewinnt einen Zusatzpunkt"<<endl<<endl;
          
          a=random(101);
          b=random(101);
          
          cout<<endl<<endl<<"Die Zufallszahl für "<<n[0]<<" lautet: "<<a;
          
          cout<<endl<<endl<<"Die Zufallszahl für "<<n[1]<<" lautet: "<<b;
          
          		if (a>b)  { cout<<endl<<endl<<n[0]<<" bekommt einen Zusatzpunkt."; k[0]++; }
          		if (b>a)  { cout<<endl<<endl<<n[1]<<" bekommt einen Zusatzpunkt."; k[0]++; }
          		if (b==a) { cout<<endl<<endl<<"Keiner bekommt einen Zusatzpunkt."; }
          
          weiter();
          
          }
          
          
          void mini3()
          {
          
          int a,b;
          
          cout<<"Minispiel Nr.3"<<endl<<endl;
          cout<<"Der Zufall entscheidet."<<endl<<endl;
          cout<<"Wer die kleinste Zahl bekommt, gewinnt einen Zusatzpunkt"<<endl<<endl;
          
          a=random(101);
          b=random(101);
          
          cout<<endl<<endl<<"Die Zufallszahl für "<<n[0]<<" lautet: "<<a;
          
          cout<<endl<<endl<<"Die Zufallszahl für "<<n[1]<<" lautet: "<<b;
          
          		if (a<b)  { cout<<endl<<endl<<n[0]<<" bekommt einen Zusatzpunkt."; k[0]++; }
          		if (b<a)  { cout<<endl<<endl<<n[1]<<" bekommt einen Zusatzpunkt."; k[1]++; }
          		if (b==a) { cout<<endl<<endl<<"Keiner bekommt einen Zusatzpunkt."; }
          
          weiter();
          
          }
          
          void spiel()
          {
          
          float p;
          
          int a,c,co,anz,feld[14],sp;
          
          k[0]=0; k[1]=0;
          
          co=3;
          
          clrscr();
          
          cout<<"Wie viele Steine: "; cin>>s[0];
          
          	while (s[0]<1) { cout<<"Wie viele Steine: "; cin>>s[0]; }
          
          		for (a=0; a<14; a++) { feld[a]=s[0]; }
          
          clrscr();
          
          cout<<"Wer Beginnt: - 1 = "<<n[0]<<endl;
          cout<<"             - 2 = "<<n[1]<<endl<<endl;
          
          cout<<"Deine Entscheidung: "; cin>>wahl[2];
          
          	while (wahl[2]!=1 && wahl[2]!=2) { cout<<"Deine Entscheidung: "; cin>>wahl[2]; }
          
          feld[6]=feld[13]=0;
          
          s[0]*=6;
          
          s[1]=s[0];
          
          	if (wahl[2]==1) sp=1; else sp=2; 
          
          clrscr(); randomize();
          
          while (s[0]>0 && s[1]>0)
          {
          
          clrscr();
          
          p=s[0]+feld[6]+k[0];
          
          p=p/(s[0]+feld[6]+k[0]+s[1]+feld[13]+k[1]);
          
          p*=100;
          
          if (wahl[1]==1) cout<<"Noch "<<co<<" Runde(n) bis zum Minispiel."<<endl<<endl;
          
          cout<<"Spieler 1:"<<endl<<endl;
          
          cout<<n[0]<<" hat eine Gewinnchance von: "; printf("%0.2f%s" , p , " %");
          
          cout<<endl<<endl;
          
          	for (a=6; a>0; a--) { cout.width(4); cout<<a; }
          
          	cout<<"   Felder Spieler 1"<<endl<<endl;
          
          		for (a=5; a>=0; a--) { cout.width(4); cout<<feld[a]; }
          
          	cout<<endl<<endl;
          
          	cout.width(4); cout<<feld[6]<<" + "<<k[0]; cout.width(12); cout<<k[1]<<" + "<<feld[13]<<"   Punkte der Spieler"<<endl<<endl;
          
          	for (a=7; a<13; a++) { cout.width(4); cout<<feld[a]; }
          
          	cout<<endl<<endl;
          
          		for (a=7; a<13; a++) { cout.width(4); cout<<a; }
          
          p-=100; p*=-1;
          
          int w;
          
          cout<<"   Felder Spieler 2";
          
          cout<<endl<<endl<<"Spieler 2:"<<endl<<endl;
          
          cout<<n[1]<<" hat eine Gewinnchance von: "; printf("%0.2f%s" , p , " %");
          
          cout<<endl<<endl;
          
          if (sp==1 || sp==2 && wahl[0]==2)
          {
          
          cout<<endl<<"Spieler "<<sp<<", welches Feld: "; cin>>w; a=w;
          
          	if (w<=6) a--; 
          
          		while (sp==1 && (w<1 || w>6 || feld[a]==0)) { cout<<"Spieler "<<sp<<", welches Feld: "; cin>>w; a=w; a--; }
          
          		       	while (sp==2 && (w<7 || w>12 || feld[a]==0)) { cout<<"Spieler "<<sp<<", welches Feld: "; cin>>w; a=w; }                       
          
          }
          
          else
          {
          
          	if (feld[12]==1)        { a=12; } else
          	if (feld[11]==2)        { a=11; } else
          	if (feld[10]==3)        { a=10; } else
          	if (feld[9]==4)         { a=9;  } else
          	if (feld[8]==5)         { a=8;  } else
          	if (feld[7]==6)         { a=7;  } else
          	if (feld[12]>=feld[11]) { a=12; } else
          	if (feld[11]>=feld[10]) { a=11; } else
          	if (feld[10]>=feld[9])  { a=10; } else
          	if (feld[9]>=feld[8])   { a=9;  } else
          	if (feld[8]>=feld[7])   { a=8;  } else a=random(7)+7;
          
          	if (a==13) a--;
                  
          		while (feld[a]==0)
          		{
          
          		a=random(7)+7;
          
          			if (a==13) a--;
          
          		}
          
          }
          
          anz=feld[a];
          
          feld[a]=0; a++;
          
          	for (c=0; c<anz; c++)
          	{
          
          		if (a==14) a=0;
          
                  feld[a]+=1; a++;
          
          	}
          
          	if (sp==1) sp=2; else sp=1;
          
          		if (wahl[2]==sp && wahl[1]==1) co--; else
          		if (wahl[2]==sp && wahl[1]==1) co--;
          
          s[0]=0; s[1]=0;
          
          		for (a=0; a<=5; a++) s[0]+=feld[a];
          
          			for (a=7; a<=12; a++) s[1]+=feld[a];
          
          	if (co==0 && wahl[1]==1)
          	{
          	co=random(3)+1;
          
          	clrscr();
          
          		if (co==1) mini1();
          		if (co==2) mini2();
          		if (co==3) mini3();
          
          	clrscr();
          
          	co=3;
          	}
          
          }
          
          s[0]=0; s[1]=0;
          
          for (a=0; a<7; a++)  { s[0]+=feld[a]; } s[0]+=k[0];
          
          for (a=7; a<14; a++) { s[1]+=feld[a]; } s[1]+=k[1];
          
          }
          
          void main(void)
          {
          
          char j={'j'};
          
          name();
          
          while (j=='j')
          {
          
          spiel(); clrscr();
          
          if (s[0]>s[1])  { cout<<n[0]<<" schlägt "<<n[1]<<" mit "<<s[0]<<" zu "<<s[1]<<" !"; u[0]++; }
          if (s[1]>s[0])  { cout<<n[1]<<" schlägt "<<n[0]<<" mit "<<s[1]<<" zu "<<s[0]<<" !"; u[1]++; }
          if (s[0]==s[1]) { cout<<n[0]<<" und "<<n[1]<<" beenden das Spiel mit einem Unentschieden !"; }
          
          cout<<endl<<endl<<n[0]<<": "<<u[0];
          cout<<endl<<endl<<n[1]<<": "<<u[1];
          
          cout<<"\n\nNochmal (j/n)"<<endl<<endl;
          
          cout<<"Deine Entscheidung: "; cin>>j;
          
          while (j!='j' && j!='n') { cout<<"Deine Entscheidung: "; cin>>j; }
          
          }
          
          }
          Ich gebe zu da am Quelltext müsste einiges gefeilt werden, aber ich wollte den Code so lassen wie ich ihn damals geschrieben habe.
          Zwar nicht wirklich toll aber wie gesagt, jeder fängt mal klein an.

          Comment

          Working...
          X