Help me with C++

I know I’m probably aren’t supposed to ask about C++ here, but i need help. I’m a beginner at C++, i actually started with C++ before HTML and CSS. Well anyway here is my code

#include <iostream>
#include <cmath>
#include <iomanip>
#include <math.h>
#include <conio.h>

using namespace std;
int main(){
	cout<<fixed << showpoint;
	cout<<setprecision(3);
	
	cout<<"A. Penjumlahan\n";
	cout<<"B. Pengurangan\n";
	cout<<"C. Perkalian\n";
	cout<<"D. Pembagian\n";
	cout<<"E. Pemangkatan\n";
	cout<<"F. Pengakaran\n";
	
	char calc = 'A', 'B', 'C', 'D', 'E', 'F';
	
	cout>>"Pilih Alat Mana?\n";
	cin<<calc;
	
	if (calc = 'A'){
		double e, g, f;
				cout<<"Penjumlahan\n------------\n";
				cout<<"Masukkan angka 1 : ";
				cin>>e;
				cout<<"Masukkan angka 2 : ";
				cin>>g;
				f = ((double)e + (double)g);
				cout<<"Hasil penjumlahan: ";
				cout<<(f);
	}
	else if (calc = 'B'){
	double h, j, l;
	cout<<"Pengurangann\n------------\n";
	cout<<"Masukkan angka 1 : ";
	cin>>h;
	cout<<"Masukkan angka 2 : ";
	cin>>j;
	l = ((double)h - (double)j);
	cout<<"Hasil pengurangan : ";
	cout<<(l);
	}
	else if (calc = 'C'){
	double x, y, z;
	cout<<"Perkalian\n------------\n";
	cout<<"Masukkan angka 1 : ";
	cin>>x;
	cout<<"Masukkan angka 2 : ";
	cin>>y;
	z = (double)x*(double)y;
	cout<<"Hasil perkalian : ";
	cout<<(z);	
	}
	else if (calc = 'D'){
	double r, s, t;
	cout<<"Pembagian\n------------\n";
	cout<<"Masukkan angka 1 : ";
	cin>>r;
	cout<<"Masukkan angka 2 : ";
	cin>>s;
	t = (double)r/(double)s;
	cout<<"Hasil pembagian : ";
	cout<<(t);
	}
	else if (calc = 'E'){
	double m, n, o;
	cout<<"Pemangkatan\n-----------\n";
	cout<<"Masukkan angka : ";
	cin>>m;
	cout<<"Masukkan pangkat : ";
	cin>>n;
	o = pow((double)m, (double)n);
	cout<<"Hasil pemangkatan : ";
	cout<<(o);
	}
	else if(calc = 'F'){
	double a, c;         
	cout<<"Pengakaran\n-----------\n";
	cout<<"Masukkan angka : ";
	cin>>a;
	c = sqrt((double)a);
	cout<<"Hasil pemangkatan : ";
	cout<<(c);	
	}
	else {
	cout>>"Tolong Pilih Huruf Lain";
	}
	return 0;
}

I can’t figure out what’s wrong. I just need this project to be finished. I will focused on JS after this.

Sure, you can ask C++ questions here - you just may not get too many answers.

I used to do C a long time ago and never did much C++.

What is this trying to do?

char calc = 'A', 'B', 'C', 'D', 'E', 'F';

And this:

	cout>>"Pilih Alat Mana?\n";
	cin<<calc;

Are you sure about those operators?

And here:

else if(calc = 'F'){

Is that the right operator?

1 Like

Hey the char is used to stores single characters. So that should mean variable calc contains those letters.

The cout is the same as console.log in JavaScript or print in Phyton.

The cin is for input from user. So that should mean that after the cout says “Pilih Alat Mana?\n”, the user can input a letter from calc. And if the user input other letter outside of calc, the computer will print “Tolong Pilih Huruf Lain” because of this code else { cout>>"Tolong Pilih Huruf Lain"; }.

else if(calc = 'F'){
This should mean that if the user input the letter ‘F’ in cin<<calc; , this double a, c; cout<<"Pengakaran\n-----------\n"; cout<<"Masukkan angka : "; cin>>a; c = sqrt((double)a); cout<<"Hasil pemangkatan : "; cout<<(c); } will run.

That is just my understanding. Maybe I have a false understanding of the codes above. I appreciate any help no matter how small. And if you need a screen shoot of the errors just tell me.

Reread that and note the words I’ve highlighted. Do you see the issue here?

Like I said, I haven’t done much C++, but I’ve never seen anything like that. What is that even supposed to mean? What is the type of the variable calc? What does it contain? If you logged it out, what would you expect it to show?

Conceptually, what do you think this is?

The cout is the same as console.log in JavaScript or print in Phyton.

Yes, I know. My issue was with the operator, >>. Are you sure that is the right operator?

The cin is for input from user…

Yes, I know. My issue was with the operator, <<. Are you sure that is the right operator?

else if(calc = 'F'){
This should mean that if the user input the letter ‘F’…

No, it doesn’t mean that. You’re confusing the assignment operator with comparison operators.

1 Like

Wait, you have errors?

  1. Why didn’t you mention that?
  2. Why don’t you investigate those?
1 Like

Thanks for your help. Yeah I wasn’t paying enough attention to my code. I guess this is just too complex for my skill. I’m gonna make a simplier version. Thanks again for your help. It really helps

1 Like

The errors really would help. It’s always helpful to include your compiler messages.

This code is pretty fixable; the issues with declaring calc and the comparison vs assignment are the main issues I see.