2 Attachment(s)
[C++]My first program ( Calculator )
I just begon C++ and this is my first program thx to guides of ragezone
Code:
#include <iostream.h>
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <iomanip.h>
#include <string.h>
int main()
{
int keuze;
long num1;
long num2;
char count;
long som;
char yesno;
menu:
system("cls");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN);
cout << "1. Calculator" << endl;
cout << "2. Exit" << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY|FOREGROUND_BLUE|FOREGROUND_GREEN);
cout << "Make your choice: " << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY|FOREGROUND_RED);
cout << "--> ";
cin >> keuze;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN);
system("cls");
if(keuze==1){ goto calculator; }
if(keuze==2){ goto exit; }
else {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY|FOREGROUND_RED);
cout << "Wrong input!" << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN);
cerr << "Press any key to continue";
getchar();
goto menu; }
calculator: //########### REKENMACHINE!!
system("cls");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN);
cout << "Number1: ";
cin >> num1;
cout << "Number2: ";
cin >> num2;
cout << "calculation (*, +, - of /):";
cin >> count;
system("cls");
if(count=='*'){ som = num1 * num2; }
if(count=='-'){ som = num1 - num2; }
if(count=='/'){ som = num1 / num2; };
if(count=='+'){ som = num1 + num2; }
cout << "outcome:" << endl;
cout << num1 << " " << count << " " << num2 << " = " << som << endl << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY|FOREGROUND_GREEN);
cout << "You want to make another calculation?" << endl << "[Y/N]: ";
cin >> yesno;
if(yesno=='y'){ goto calculator; }
if(yesno=='n'){ goto menu; }
else { goto confirm_calc; }
confirm_calc:
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY|FOREGROUND_RED);
cout << endl << endl << endl << "Wrong input!" << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY|FOREGROUND_GREEN);
cout << "Do you want to make another calculation?" << endl << "[Y/N]: ";
cin >> yesno;
if(yesno=='y'){ goto calculator; }
if(yesno=='n'){ goto menu; }
else { goto confirm_calc; } //########### REKENMACHINE!!
exit:
return 0;
}
Attachment 47897
Attachment 47898
With me they work so I hope it was a nice first try :p
All comments are welcome
Re: [C++]My first program ( Calculator )
lol i did see this somewere on google looks complete the same only you changed some collors
Re: [C++]My first program ( Calculator )
I followed a guide on a website but it was just info not something like this one
Re: [C++]My first program ( Calculator )
sec ill google and post it you will see
Re: [C++]My first program ( Calculator )
K then please post me a link , but i realy used a guide for it
i didnt use full code
Re: [C++]My first program ( Calculator )
PSC?
Seem's alot like it.
Re: [C++]My first program ( Calculator )
Quote:
Originally Posted by
passie
lol i did see this somewere on google looks complete the same only you changed some collors
Owh my god, someone copied DOS STYLE CALCULATOR, jail him!!
Chill man, it's not worth it anyway.
Good work on first project, but it has some bad aspects like when I can enter letters there, so bsically i can make something like this: 3 Z 4 = ?? :biggrin:
Or something like this:
3 ZWSAGHGDA 4 = BUG :)
Practise more, make application with GUI, good luck. :clap:
Re: [C++]My first program ( Calculator )
It's nice but I guess it'll be better if you actually add in different buttons such as, "EVAPORATE" for erasing the numbers, or "ELIMINATE" for closing the program.
That's just an IDEA.
Anyways, nice Calculator, works fine / pretty good.