r/learncpp • u/Knotaipaendragthetoy • Apr 08 '20
Could someone critique my code please?
#include <iostream>
#include <cmath>
#include <math.h>
#include <string>
using std::istream, std::string, std::ostream, std::sqrt, std::endl, std::cout, std::cin;
int main()
{
double_t MonsterMath;
double_t Frank;
cout << "Type in a number and I'll square it! " << endl;
cin >> MonsterMath;
cout << sqrt(MonsterMath)<< endl;
cout << "Ok, now type it back to me! "<< endl;
cin >> Frank;
cout << (MonsterMath == Frank ? "Great Job " : "Wrong Loser ");
return 0;
}
I'm barely starting out and so any guidance like say incorrect style or whatnot would be fantastic.
2
Upvotes
View all comments
Show parent comment
1
u/xkompas May 01 '20
I would add comparing doubles with
==is bad style and may not work as expected, especially if computation is involved (which does not apply here).Also, variables usually do not start with capital letters, that is the convention for types.