I've been learning a ton of c++ lately on Codecademy and I'm soon done with the course of c++.
(Still need to learn classes, object-oriented programming and harder projects.)
But I wanted to get a review of my recent program.
And I also wanted to know if its possible to make an Unique ID, that only fits me, kinda like the cicada.
Psst, the program is to solve Ohm's Formular in physics and actively takes input to solve exactly your case.
Leave suggestions on what I could do better in this project + what I should try to program next too.
//Include
#include <iostream>
#include <string>
using namespace std;
int main(){
//Declare variables
double Wolt;
double Ohm;
double Amp;
std::string Formular;
std::string Username;
std::string Whitelist;
//Login sequence:
std::cout << "Hvad er dit username?: ";
cin >> Username;
//Whitelist
Whitelist = "Fred267s", "Seb4572s", "Popp4593s";
//Check if username is on whitelist
if (Username == Whitelist){
std::cout << "Velkommen til fysik formel udregner til strøm " << Username << " \n";
std::cout << "Lavet af Frederik Schmidt 1.S \n";
}
//If username is NOT on the whitelist
else if (Username != "Fred267s", "Seb4572s", "Popp4593s" ){
std::cout << "Sorry, you do not have access! \n";
return 0;
}
//Questions
std::cout << "Hvad er det du skal udregne? ";
cin >> Formular;
//Wolt formular
if (Formular == "Wolt"){
//Questions
std::cout << "Hvad er Ohmen?: ";
cin >>Ohm;
std::cout << "Hvad er Amperen?: ";
cin >> Amp;
//Formular
Wolt = Ohm*Amp;
//Return
std::cout << "Volten er: " << Wolt << " \n";
}
//Amp formular
else if (Formular == "Amp"){
//Questions
std::cout << "Hvad er Volten?: ";
cin >>Wolt;
std::cout << "Hvad er Ohmen?: ";
cin >>Ohm;
//Formular
Amp = Wolt/Ohm;
//Return
std::cout << "Amperen er: " << Amp << " \n";
}
//Ohm formular
else if (Formular == "Ohm"){
//Questions
std::cout << "Hvad er Volten?: ";
cin >>Wolt;
std::cout << "Hvad er Amperen?: ";
cin >>Amp;
//Formular
Ohm = Wolt/Amp;
//Return
cout << "Ohmen er: " << Ohm << " \n";
}
//If the Formular inputtet is NOT on the list.
else {
cout << "Error in the formular, please try again!";
}
}
using namespace std;
, so that you don't pollute your namespace with lots of stuff you probably don't need anyway. However, if you do add it, it's redundant to write code likestd::cout
, you can writecout
only \$\endgroup\$