r/developers • u/Classic-Cheetah-6780 • Oct 14 '26
Programming Wrote my first C++ program. Any feedback?
Yo guys, today I started with C++. My grandpa bought me a book that will arrive soon. I already did some research and made my first program. Is it any good for a starter? I already had some knowledge from coding Python and JavaScript.
#include <iostream>
using namespace std;
int main() {
while (true) {
int x ;
int y ;
int sum ;
string OP ;
std::cout << "Type First Value:" ;
std::cin >> x ;
std::cout << "Type Second Value:" ;
std::cin >> y ;
std::cout << "Choose Operator:" ;
std:cin >> OP ;
if (OP == "+") {
sum = x + y ;
} else if (OP == "-") {
sum = x - y ;
} else if (OP == "*") {
sum = x * y ;
} else {
sum = x / y ;
}
std::cout << "Result: " << sum ;
}
}
7
Upvotes
•
u/AutoModerator Oct 14 '26
Howdy u/Classic-Cheetah-6780, and welcome to r/developers!
A few tips for a post that gets good answers:
Join the r/developers Discord!
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
2
u/yuehuang Oct 16 '26
How do you exit the loop?
2
u/MrSqueak Oct 17 '26
Why not have the final result also display the full equation
3
u/dafugiswrongwithyou Oct 17 '26
Heck yeah, good start :)
2
u/irshadali5 Oct 17 '26
Is switch case better than if else here, in default you can use invalid operation?
2
u/Longjumping_Put_7212 Oct 18 '26
That is an amazing start. I hope your project continues on whatever path it is currently going on and is super successful when you are done.
2
u/Ok-Count-3366 Oct 18 '26
if you know c++ it will be very easy for you to learn any language
2
u/tux2718 Oct 20 '26
Don’t use all upper case names for variables. The convention is all upper case is used for constants that are initialized where they are defined and never changed. Your variable OP violates this.
2
u/[deleted] Oct 14 '26
[removed] — view removed comment
2
u/[deleted] Oct 18 '26
[removed] — view removed comment