Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Frage zu cin/scanf Taschenrechner

Empfohlene Antworten

Veröffentlicht

Ahoi,

der Titel sagt zwar nicht gerade viel aus, aber das werd ich jetzt mal erklären ;D.

Da ich überall gesehen habe das Leute Taschenrechner machen, wollte ich es auch einmal probieren, jedoch etwas anders.

Die meisten nutzten ja Funktionen dazu, also zb. am Anfang die frage mit welchem Operator wollen sie Rechnen, addition, subtraktion usw..

Nun war mir das aber zu blöd, denn ein richtiger Taschenrechner fragt das ja auch nicht ab. Also kam ich auf die idee es gleich mit in die Eingabe des Users zu implementieren. Da ich aber nicht wusste wie ich das machen soll, da ja in scanf nur 1 was reinpasst ( denke ich jedenfalls ), habe ich in verschiedenen Foren nach einer Lösung gesucht und schließlich hatte eine einzige Person die Lösung. Hier der Quelltext:

#include <cstdlib>

#include <iostream>

using namespace std;

int main(int argc, char *argv[])

{

cout << "Taschenrechner" << endl;

cout << "==============" << endl << endl;

double a,b;

float E;

char r;

cout << "Rechnung: "; cin >> a >> r >> b;

cout << "_________________" << endl;

switch®

{

case '+': E = a + b; break;

case '-': E = a - b; break;

case '*': E = a * b; break;

case '/': E = a / b; break;

}

cout << "Ergebnis: " << E << endl << endl;

system("PAUSE");

return 0;

}

Das ist zwar schon eine Lösung aber es klärt nicht alles. Die Zeile mit

cout << "Rechnung: "; cin >> a >> r >> b;

war die Lösung, jedoch würde ich gerne wissen wie das mit printf und scanf aussieht und ob es überhaupt machbar ist.

Kennt jemand die Lösung ?

Danke, Robert.

Problem gelöst:

printf("Rechnung:\n);

scanf("%lf %c %lf", &a, &r, &B);

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.