.ccls-cache
.gitignore
main
main.cpp
Makefile
Config files
.replit
replit.nix
// Code written by Daniele Pio Pica
#include <iostream>
#include <string.h>
using namespace std;
void moles_program();
void mass_program();
void molar_mass_program();
int main()
{
string Choice;
cout<<" <<Chemistry Calulator>>"<<endl;
cout<<"_______________________________________________________________________"<<endl;
cout<<"--> Choose the unknown asked by the problem: "<<endl;
cout<<"--> Digit 'Moles' to find the moles;"<<endl;
cout<<"--> Digit 'Mass' to find the mass;"<<endl;
cout<<"--> Digit 'Molar_Mass' to find the molar mass;"<<endl;
cout<<"_______________________________________________________________________"<<endl;
cout<<"-->Your choice: ";
cin>>Choice;
cout<<"_______________________________________________________________________"<<endl;
if (Choice=="Moles" || Choice=="moles")
{
moles_program();
}
else if (Choice=="Mass" || Choice=="mass")
{
mass_program();
}
else if (Choice=="Molar_Mass" || Choice=="molar_mass")
{
molar_mass_program();
}
else
{
cout<<"Syntax Error."<<endl;
}
return 0;
}
void moles_program()
{
int I=0, Atoms_Number;
float Mass, Atomic_Mass, Counter, Molar_Mass, Moles;
cout<<"--> Digit the mass given by the problem (in g): ";
cin>>Mass;
cout<<"--> Digit how many the atoms are: ";
cin>>Atoms_Number;
cout<<"--> Digit the atomic mass of the atom: ";
cin>>Atomic_Mass;
Counter=Atomic_Mass;
Molar_Mass=Atomic_Mass;
while (I<Atoms_Number - 1)
{
Counter=Molar_Mass;
cout<<"--> Digit the atomic mass of the atom: ";
cin>>Atomic_Mass;
Molar_Mass=Counter+Atomic_Mass;
I++;
}
Moles=Mass/Molar_Mass;
cout<<"_______________________________________________________________________"<<endl;
cout<<"--> The moles are: "<<Moles<<" mol."<<endl;
}
void mass_program()
{
int I=0, Atoms_Number;
float Mass, Atomic_Mass, Counter, Molar_Mass, Moles;
cout<<"--> Digit the moles given by the problem (in mol): ";
cin>>Moles;
cout<<"--> Digit how many the atoms are: ";
cin>>Atoms_Number;
cout<<"--> Digit the atomic mass of the atom: ";
cin>>Atomic_Mass;
Counter=Atomic_Mass;
Molar_Mass=Atomic_Mass;
while (I<Atoms_Number - 1)
{
Counter=Molar_Mass;
cout<<"--> Digit the atomic mass of the atom: ";
cin>>Atomic_Mass;
Molar_Mass=Counter+Atomic_Mass;
I++;
}
Mass=Moles*Molar_Mass;
cout<<"_______________________________________________________________________"<<endl;
cout<<"--> The mass is: "<<Mass<<" g."<<endl;
}
void molar_mass_program()
{
int Atoms_Number, I=0;
float Atomic_Mass, Counter, Molar_Mass;
cout<<"--> Digit how many the atoms are: ";
cin>>Atoms_Number;
cout<<"--> Digit the atomic mass of the atom: ";
cin>>Atomic_Mass;
Counter=Atomic_Mass;
Molar_Mass=Atomic_Mass;
while (I<Atoms_Number - 1)
{
Counter=Molar_Mass;
cout<<"--> Digit the atomic mass of the atom: ";
cin>>Atomic_Mass;
Molar_Mass=Counter+Atomic_Mass;
I++;
}
cout<<"_______________________________________________________________________"<<endl;
cout<<"--> The molar mass is: "<<Molar_Mass<<" g/mol."<<endl;
}