Informatiker Board (http://www.informatikerboard.de/board/index.php)
- Themengebiete (http://www.informatikerboard.de/board/board.php?boardid=1)
-- Informatik in der Schule (http://www.informatikerboard.de/board/board.php?boardid=21)
--- Programieren (http://www.informatikerboard.de/board/thread.php?threadid=1374)


Geschrieben von eulerscheZahl am 13.02.2013 um 18:30:

 

Es klappt bei dir noch nicht alles: Wenn die Zahl <= 0 ist, bekommst du die Meldung, die Zahl sei zu groß, obwohl sie zu klein ist.

Mit string sieht das dann so aus:
code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

int main() 
{
	string s1;
	int Zahl;
	cout << "Geben Sie eine Zahl zwischen 1 bis 100 an!  ";
	cin >> s1;
	Zahl = atoi(s1.c_str());
	if(Zahl >= 1 && Zahl <= 100)
		cout << setprecision(2) << fixed << setw(6) << right << s1 << endl;
	else if(Zahl < 1)
		cout << " Die angegebene Zahl ist zu klein!" << endl;
	else
		cout << " Die angegebene Zahl ist zu gross!" << endl;
	system("PAUSE");
	return 0;
}



Geschrieben von info am 13.02.2013 um 20:34:

 

Naja leider scheint das programm mit string nicht zu funktioieren.

Aber ok das Prinzip habe ich aber verstanden.


Forensoftware: Burning Board, entwickelt von WoltLab GmbH