Merhaba arkadaşlar bu makalemizde C++ da toplama,çıkarma, çarpma ve bölme gibi dört işlemin nasıl gerçekleştirildiğini bu örneğimizde göreceğiz..
Şekil 1
cpp_calculator.h
#pragma once
#pragma once
int main()
{
float sayi1, sayi2, sonuc;
using namespace std;
int secim;
do
{
cout << "1. Toplama (Addition)\n";
cout << "2. Cikarma (Subtraction)\n";
cout << "3. Carpma (Multiplication)\n";
cout << "4. Bolme (Division)\n";
cout << "5. Cikis (Exit)\n\n";
cout << "Lutfen 1-5 arasindaki islemi secip entere tiklayiniz..Enter Your Choice(1-5): ";
cin >> secim;
if (secim >= 1 && secim <= 4)
{
cout << "\n Iki sayi giriniz..Enter any two numbers: ";
cin >> sayi1 >> sayi2;
}
switch (secim)
{
case 1:
sonuc = sayi1 + sayi2;
cout << "\nResult = " << sonuc;
break;
case 2:
sonuc = sayi1 - sayi2;
cout << "\nResult = " << sonuc;
break;
case 3:
sonuc = sayi1 * sayi2;
cout << "\nResult = " << sonuc;
break;
case 4:
sonuc = sayi1 / sayi2;
cout << "\nResult = " << sonuc;
break;
case 5:
return 0;
default:
cout << "\nOoops!Yanlis secim girisi!Wrong Choice!";
break;
}
cout << "\n------------------------\n";
} while (secim != 5);
cout << endl;
return 0;
}
cpp_calculator.cpp
// cpp_calculator.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include "cpp_calculator.h"
using namespace std;
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu
// Tips for Getting Started:
// 1. Use the Solution Explorer window to add/manage files
// 2. Use the Team Explorer window to connect to source control
// 3. Use the Output window to see build output and other messages
// 4. Use the Error List window to view errors
// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
Bir makalenin daha sonuna geldik. Bir sonraki makalede görüşmek üzere. Bahadır ŞAHİN
0 comments:
Yorum Gönder