Jump to content

Recommended Posts

Posted

Presupunand ca orice post poate ajuta candva pe cineva , poftim un programel in c++ , un calculator mai exact , bazat pe functia switch si pentru afisarea pe ecran a operatiilor am folosit vectori.

#include<iostream>
#include<cstdlib>
#include<conio.h>
#include<vector>
/* Autor : BGD 1337
Progamming Language - C++
Scope : Can be useful for a begginer.
*/
using namespace std;
int main(){
int a,b;
char choise;
vector<string> operatii;
vector<string>::iterator iter;
cout <<"\t\tCalculator pe sectiuni de operatii\n\n";
operatii.push_back("Inmultire");
operatii.push_back("Adunare");
operatii.push_back("Scadere");
operatii.push_back("Impartire");
restart:
cout<<"Alege operatia dorita\n\n";
for (iter = operatii.begin(); iter != operatii.end(); iter++)
cout << *iter << endl;
int alege;
cout<<"\nAlege: ";cin>>alege;
switch(alege){
case 1: cout<<"Ai ales operatia de inmultire , acum poti calcula\n\n";
cout<<"a=";cin>>a;
cout<<"b=";cin>>b;
cout<<"Rezultatul este " <<a*b<<endl;
cout <<"\nDoresti sa iesi din program ?[Y/N]\n";
choise=_getch();
if (choise == 'n')
goto restart;
break;
case 2: cout<<"Ai ales operatia de adunare , acum poti calcula\n\n";
cout <<"a=";cin>>a;
cout <<"b=";cin>>b;
cout <<"Rezultatul este " <<a+b<<endl;
cout <<"\nDoresti sa iesi din program ?[Y/N]\n";
choise=_getch();
if (choise == 'n')
goto restart;
break;
case 3: cout<<"Ai ales operatia de scadere , acum poti calcula\n";
cout <<"a=";cin>>a;
cout <<"b=";cin>>b;
cout <<"Rezultatul este " <<a-b<<endl;
cout <<"\nDoresti sa iesi din program ?[Y/N]\n\n";
choise=_getch();
if (choise == 'n')
goto restart;
break;
case 4: cout<<"Ai ales operatia de impartire , acum poti calcula\n\n";
cout <<"a=";cin>>a;
cout <<"b=";cin>>b;
cout <<"Rezultatul este " <<a/b<<endl;
cout <<"\nDoresti sa iesi din program ?[Y/N]\n\n";
choise=_getch();
if (choise == 'n')
goto restart;
break;
default: cout<<"Nu exista aceasta operatie";
cout <<"\nDoresti sa iesi din program ?[Y/N]\n";
choise=_getch();
if (choise == 'n')
goto restart;
}
cin.ignore(cin.rdbuf()->in_avail() +1);
getchar();
return 0;
}

Posted
Mi-a dat o eroare la getchar();. Eroare ce s-a rezolvat folosind un #include<stdio.h>. In rest e ok. Este super bun programul pentru incepatori!

Eu stiu ca getchar() se afla in libraria conio.h . In orice caz programul va functiona si fara acesta deoarece linia cin.ignore(cin.rdbuf()->in_avail() +1); are la randul ei rolul de a tine fereastra deschisa.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...