Programming in C++

I’ve made it far enough in my the BeginnersCPP.com tutorials that I was able to tackle the first of their code challenges! The goal was to write a program that could determine whether or not a number was a prime number. I did have to look up how to determine whether there would be remainders when dividing, but it turns out that was very similar to Python! This is what I came up with:

#include 

using namespace std;
int main(){

	int number;

	cout << "Enter a number: \n";
	cin >> number;

	if ((number == 3) || (number==5) || (number==7)){
		cout <<"Your number is a prime number.\n";
	}

	else if ((number%2==0) || (number%3==0) || (number%4==0) || (number%5==0) || (number%6==0) || (number%7==0) || (number%8==0) || (number%9==0)){
		cout << "Your number is not a prime number.\n";
	}

	else {
		cout << "Your number is a prime number.\n";
	}


	return (0);
}

I have been pleasantly surprised with C++. I thought that it was going to be more of a challenge to learn the syntax but so far it hasn’t been that bad. Now that I’ve gotten the basics of C++ down I might go back to some of the other Python courses that I was in the middle of before I had to switch gears for a bit. But I feel a little bit more confident for when I will need to go further into C++ or when I’ll be using it in school! Speaking of, I registered for my first two classes, which start in June. It seems like a while away but it’ll probably sneak up on me!

Read More Post