hi, i'm trying to make a molar mass calculator where you have to input the name/symbol of the element and the multiplier to compute it. my problem is, if the user enters the wrong element (element does not exist or typo), i want the program to keep asking until he/she gets it right.. here's what i did so far (haven't inputted all the elements yet)
:
#include <iostream>
#include <conio.h>
#include <windows.h>
#include <cmath>
#include <string>
using namespace std;
int main()
{
double mm1=0, mm2=0, mm3=0, mmtot=0, mmtoteng=0;
int option=0, mole1=0, mole2=0, mole3=0;
string name;
string sym1;
string sym2;
string sym3;
char yesno;
cout<<"To start program, please enter your name: ";
cin>>name;
getch();
system("cls");
cout<<"Hello, "<<name<<"! Welcome to XYIENTIST MOLAR MASS CALCULATOR.\n\n";
cout<<"Compute for: \n\n[1]Element\n[2]Polyatomic Molecule\n[3]Two-element Compound\n[4]Three-element compound";
cout<<"\nEnter option: ";
cin>>option;
getch();
system("cls");
if (option==3)
{
do
{
cout<<"Enter first element name or symbol:";
char element1[20];
cin>>element1;
cout<<"Enter number of moles of element1: ";
cin>>mole1;
if ((stricmp ("Hydrogen",element1) == 0) || (stricmp ("H",element1) == 0))
{
mm1=1.008;
sym1='H';
}
else
{
cout<<"\nNo such element exists!";
}
}
while (stricmp(element1,element1)!=0);
cout<<"Enter 2nd element name or symbol:";
char element2[20];
cin>>element2;
cout<<"Enter number of moles of element2: ";
cin>>mole2;
if ((stricmp ("Carbon",element2) == 0) || (stricmp ("C",element2) == 0))
{
mm2=12.01;
sym2='C';
}
cout<<"Enter 3rd element name or symbol:";
char element3[20];
cin>>element3;
cout<<"Enter number of moles of element3: ";
cin>>mole3;
if ((stricmp ("Oxygen",element3) == 0) || (stricmp ("O",element2) == 0))
{
mm3=16.00;
sym3='O';
}
cout<<"\n\nCompound is "<<sym1<<mole1<<sym2<<mole2<<sym3<<mole3<<" .";
mmtot=(mm1*mole1)+(mm2*mole2)+(mm3*mole3);
cout<<"\nMolar mass is:"<<mmtot;
}
else
cout<<"Invalid!";
return 0;
}
how do i loop the program? thanks.