Hallo,
Ik ben nog steeds nieuw met C++ maar na veel leren en proberen vindt ik het toch waard met eerste creatie tentoon te stellen.
Ik was niet zeker waar ik het mocht posten omdat dit niet echt een spectaculaire creatie is, maar vindt het toch de moeite waard.
Suggesties en verbeteringen zijn altijd welkom en ik zal de updates die ik ga uitvoeren als ik meer geleerd heb ook hier posten.
De rekenmachine kan nog niet met floats werken, ga ik binnenkort doen. Momenteel kan hij:
+, -, /, *, % en vierkantswortel uitrekenen.
#include <iostream>
using namespace std;
int calculate(int a, char c[1], int b)
{
if(strstr(c, "+"))
{
int answer = a + b;
system("cls");
return answer;
}
if(strstr(c, "-"))
{
int answer = a - b;
system("cls");
return answer;
}
if(strstr(c, "*"))
{
int answer = a * b;
system("cls");
return answer;
}
if(strstr(c, "/"))
{
int answer = a / b;
system("cls");
return answer;
}
if(strstr(c, "%"))
{
int answer = a / 100 * b;
system("cls");
return answer;
}
else
{
cout << "You entered a wrong character" << endl;
system("PAUSE");
return 0;
}
system("PAUSE");
return 0;
}
int sqroot(int a)
{
int z = 2;
for(int i = 0; i < a; i++)
{
int y = a / z;
if(i == y)
{
i++;
system("cls");
return (i);
}
z++;
}
cout << "something wrong on sqroot code" << endl;
system("PAUSE");
return 1;
}
int main()
{
int a;
int b;
char c[1];
system("color 0E");
cout << "Enter the first number you want to use" << endl;
cin >> a;
cout << "Press +" << endl;
cout << "Press -" << endl;
cout << "Press *" << endl;
cout << "Press /" << endl;
cout << "Press %" << endl;
cout << "Press v for square root\n" << endl;
cout << "Enter the charachter that matches with what you want to do" << endl;
cin >> c;
if(strstr(c, "v"))
{
int z;
z = sqroot(a);
cout << "The answer is " << z << endl;
}
else
{
cout << "Enter the second number you want to use" << endl;
cin >> b;
int answer;
answer = calculate(a, c, b);
cout << "The answer is " << answer << endl;
}
system("PAUSE");
return 0;
}
http://Drekes.funpic.org/calculator.exe