[ create a new paste ] login | about

Link: http://codepad.org/EdVl5K9T    [ raw code | output | fork ]

C++, pasted on Oct 7:
#include <iostream>
#include <math.h>

using namespace std;

void ende();					// Prototyp
void schleife();				// Prototyp

int main ()
{
	// VARIABLEN
	//
	int Bit;					// Bitanzahl n
	int Kombinationen;			// Anzahl Kombinationen K
	int Zahl;					// größte darstellbare Zahl m

	// Abfrage der Bitanzahl n
	do
	{
		system("CLS");
		cout << "\nBitanzahl n: ";
		cin >> Bit;
	}
	while (Bit > 30);			// größer als 30 nicht möglich

	// Berechnen von K und m
	Kombinationen = pow (2.0f, Bit);
	Zahl = pow (2.0f, Bit) - 1;

	// Ausgabe von K und m
	cout << "----------------" << "\n\n";
	cout << "Anzahl Kombinationen K: ";
	cout << "\t" << Kombinationen << "\t| Adresse:\t" << &Kombinationen << endl;
	cout << "Groesste darstellbare Zahl m: ";
	cout << "\t" << Zahl << "\t| Adresse:\t" << &Zahl << endl;
	cout << "\n\n";
	system("PAUSE");
	ende();

	return 0;
}

// Auswahl Programmende
void ende()
{
	int Auswahl = 0;

	do
	{
		system("CLS");
		cout << "\n\t[1] Weiter";
		cout << "\n\t[2] Schleife" << "\n\n";
		cout << "\t[3] Beenden" << "\n\n";
		cout << "\t    Eingabe: ";
		cin >> Auswahl;

		if (Auswahl == 1)
		{
			main();
		}

		else if (Auswahl == 2)
		{
			schleife();
		}

		else if (Auswahl == 3)
		{
			system("EXIT");
		}
	}
	while (Auswahl > 3);		// größer als 2 nicht möglich
}

void schleife()
{
	int Bit;					// Bitanzahl n
	int Kombinationen;			// Anzahl Kombinationen K
	int Zahl;					// größte darstellbare Zahl m

	system("CLS");

	// Abfrage der Bitanzahl n (Startzahl)
	do
	{
		system("CLS");
		cout << "\nMenge: ";
		cin >> Bit;
	}
	while (Bit > 30);			// größer als 30 nicht möglich

	system("CLS");

	for (int i=0; i<Bit; i++)
	{
		Kombinationen = pow (2.0f, i);
		Zahl = pow (2.0f, i) - 1;

		// Ausgabe von K und m
		cout << "\n\n";
		cout << i << " Bit: ";
		cout << "\tAnzahl Kombinationen K:" << Kombinationen << "\t" << "Groesste darstellbare Zahl m:" << Zahl;
	}

	cout << "\n\n";
	system("PAUSE");
	ende();
}


Output:
1
2
3
4
5
6
7
cc1plus: warnings being treated as errors
In function 'int main()':
Line 27: warning: converting to 'int' from 'float'
Line 28: warning: converting to 'int' from 'float'
In function 'void ende()':
Line 59: error: ISO C++ forbids taking address of function '::main'
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: