Einzelnen Beitrag anzeigen

Benutzerbild von 3_of_8
3_of_8

Registriert seit: 22. Mär 2005
Ort: Dingolfing
4.129 Beiträge
 
Turbo Delphi für Win32
 
#4

Re: [C++] Problem bei Stringverleich

  Alt 8. Feb 2006, 20:12
OK, hier mal mein ganzer Code, funzt nämlich immer noch nicht. Und == hat Vorrang vor ||.

Code:
#include <iostream.h>
#include <stdio.h>

int main(void){
 char op[1];
 int oprnd1, oprnd2, result;
 while(true){
  cout<<"Bitte geben sie einen arithmetischen Operator ein: ";
  cin>>op;
  if(op=='+'||op=='-'||op=='*'||op=='/') break;
  cout<<"Ungültiger Operator: "<<op<<"\n";
 }
 cout<<"Bitte geben sie den ersten Operanden ein: ";
 cin>>oprnd1;
 cout<<"Bitte geben sie den zweiten Operanden ein: ";
 cin>>oprnd2;
 if(op=="+") cout<<oprnd1<<"+"<<oprnd2<<"="<<oprnd1+oprnd2;
 if(op=="-") cout<<oprnd1<<"-"<<oprnd2<<"="<<oprnd1-oprnd2;
 if(op=="*") cout<<oprnd1<<"*"<<oprnd2<<"="<<oprnd1*oprnd2;
 if(op=="/") cout<<oprnd1<<"/"<<oprnd2<<"="<<oprnd1/oprnd2;
 getchar();
}
Manuel Eberl
„The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it.“
- Terry Pratchett
  Mit Zitat antworten Zitat