Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 18:32

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Switch in C++

Discussion on Switch in C++ within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 1
Join Date: Nov 2010
Posts: 155
Received Thanks: 21
Exclamation Switch in C++

Hi ich hab ein Problem bei der Switch-Funktion:

Code:
// Quadratzahlengenerator.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung.
//


#include "stdafx.h"
#include <string>
#include <iostream>
#include <Windows.h>
#include <math.h>
using namespace std; 


int _tmain(int argc, _TCHAR* argv[])
{
int Quadrz ;
cout << endl ;
cout << "Menue: " << endl ;
cout << "Quadratzahlengenerator         <1>" << endl ;
cout << "Formelanzeige                  <2>" << endl ;


cin >> Quadrz ;
Sleep (1000) ;


}
	




[color=#ff0000]switch[/color] (Quadrz) ;
[color=#ff0000]{[/color]
case 1:
	int d  ;
	int x  ;
	int x2 ;
	int y2 ;
	
	cout << "Geben sie eine ungerade Zahl fuer d ein." << endl ;
	cin >> d ;
	x = (d - 1.0) / 2.0 ;
	cout << " x ist  gleich " << x << endl ;
	Sleep (2500) ;
	x2 = x * x ;
	cout << "x^2 ist gleich " << x2 << endl ;
	Sleep (2500) ;
	y2 = x2 + d ;
	cout << "y^2 ist gleich " << y2 << endl ;
	Sleep (2500) ;
	
	Sleep (2000) ;
	getchar () ;
	
	[color=#ff0000]break[/color] ;
	

[color=#ff0000]case[/color] 2:
	cout << "Danke, das Sie sich für neue Funktionen entscheiden." << endl ;
	[color=#ff0000]break[/color] ;

[color=#ff0000]default[/color]:
	cout <<"Benutzen Sie bitte nur die Taste 1 und 2." << endl ;

}

{
getchar () ;
return () ;
}

Das Rote wird als falsch unterstrichen.
green.green is offline  
Old 01/06/2011, 19:44   #2
 
elite*gold: 0
Join Date: Apr 2006
Posts: 6,597
Received Thanks: 1,830
wie wärs mit fehlermeldung lesen?
in der switch zeile gehört kein semikolon hin.
Medix is offline  
Old 01/06/2011, 19:49   #3
 
elite*gold: 0
Join Date: May 2010
Posts: 793
Received Thanks: 268
ist ja auchnicht inner halb einer funktion.
nkkk is offline  
Old 01/06/2011, 20:11   #4
 
elite*gold: 0
Join Date: Apr 2006
Posts: 6,597
Received Thanks: 1,830
Das kommt noch hinzu.

Ich würd mal das zeugs alles löschen und bei kapitel 1 in deinem Buch/tutorial anfangen.
Medix is offline  
Old 01/14/2011, 19:54   #5
 
Telithanor's Avatar
 
elite*gold: 0
Join Date: Jan 2010
Posts: 21
Received Thanks: 1
ist doch eig. ganze einfach

so müsste es eig richtig heißen:


Quote:
int _tmain(int argc, _TCHAR* argv[])
{
int Quadrz ;
cout << endl ;
cout << "Menue: " << endl ;
cout << "Quadratzahlengenerator <1>" << endl ;
cout << "Formelanzeige <2>" << endl ;


cin >> Quadrz ;
Sleep (1000) ;

switch (Quadrz) ;
{
case 1:
int d ;
int x ;
int x2 ;
int y2 ;

cout << "Geben sie eine ungerade Zahl fuer d ein." << endl ;
cin >> d ;
x = (d - 1.0) / 2.0 ;
cout << " x ist gleich " << x << endl ;
Sleep (2500) ;
x2 = x * x ;
cout << "x^2 ist gleich " << x2 << endl ;
Sleep (2500) ;
y2 = x2 + d ;
cout << "y^2 ist gleich " << y2 << endl ;
Sleep (2500) ;

Sleep (2000) ;
getchar () ;

break ;


case 2:
cout << "Danke, das Sie sich für neue Funktionen entscheiden." << endl ;
break ;

default:
cout <<"Benutzen Sie bitte nur die Taste 1 und 2." << endl ;

}
...

}
...
Fehler:

switch musst du dir vorstellen wie etwa eine if-abfrage.
die variable dafür also Quadrz ist ja in _tmain deklariert. außerhalb dieser funktioniert ist diese variable ungültig. und deswegen kannst du sie außerhalb dieser nicht benutzen.

und 2ten muss switch innerhalb der funktion stehen


hoffe konnte helfen, auch wenn der thread einige tage alt ist
Telithanor is offline  
Reply


Similar Threads Similar Threads
Dss switch rek
05/10/2011 - Metin2 - 10 Replies
Wollte mal wissen was ihr für erfahrung gemacht habt mit dss switch vom rek. zB habe ein rek mit 15%dss und eins mit 27%dss und bin am überlegen ob ich meine dr (drachenmünzen) für "Gegenstand verzaubern" mal investieren sollte. Das Rek sollte dann schon 41dss habe und mehr:rolleyes:. Hat jemnd damit schon erfahrung gemacht? Und wenn ja wieviel "Gegenstand verzaubern" musstest du investieren?
switch off your name
05/09/2011 - Archlord Trading - 5 Replies
sorry if this should have gone in another section or has already been posted but ive seen a lot of people posting pics where you can still see their name in the background. webzen might not give a rats at the moment but maybe one day they will start banning so to prevent this just turn off your name in the options menu. http://i40.tinypic.com/dxdy6v.jpg simples
DSS Switch Bot?!
02/01/2011 - Metin2 Private Server - 10 Replies
Hallo Liebe Com. Da ich schon gesehen habe das es einer hinbekommen hat, einen Bot zu Skripten der die bonies solange switcht bis z.b. etwas zwischen 30-39 dss heraus kommt und dann aufhört. Aber dieser funzt bei fast keinem.. Und geht nur mit Waffen die 3 Steinslots bestizen also nur Nun ist meine Frage ob es villeicht jemand schaft einen solchen Bot richtig zu skripten das dieser voll funktionstüchtig ist. Und auch oder nur VMS switchen kann, und man einstellen kann das er erst dann...
NT BOT cd key switch
03/30/2009 - Diablo 2 - 1 Replies
also hab jetzt ne MPQ datei erstellt in den diablo 2 ordner also mein zweiter cd key meine frage jetzt hab ich ein cd key installiert und von ein cd key eine mpq datei erstellt wie muss ich das beim ntbot manager eingeben da steht jetzt an der seite wie viele cd keys man benutzt soll ich jetzt 2 keys eingeben oder 1 ??? weil hab jetzt 1 cd key angegeben und in die leiste CDKEY!.mpq reingeschrieben aber wenn er jetzt ein game gemacht hat restartet er diablo 2 wieso ??
FB and SS switch?
02/05/2006 - Conquer Online 2 - 8 Replies
Hey guys, I was just wondering if there was anyway to change the FB image with the SS image. I know it sounds weird but i can aim better with the ss image..Please help me or PM me. Thanks guys. btw...I love all your guys work.Ill start to post more. lolx :bandit: :bandit: :bandit: :bandit:



All times are GMT +1. The time now is 18:33.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.