Ok I just started programming again after about 10 years,
and i was doing the suggested beginner problems.
The first one to create a program that returns the factorial of a number.
I think i got it all down right but compiler is saying
"expected primary-expression before else"
here's the code, I made the places the compiler doesn't like magenta.
#include <iostream>
using namespace std;
int main () {
cout << "This program gives you the factorial of your number.\n";
cout << "Please enter a number. ";
int num, prime = 2;
cin >> num;
if (num == 0 || num == 1) {prime = num;}
if (num < 0) {
cout << "This program only handles positive numbers.";
system ("pause");
return 0;}
int max = num, E = 1;
while ((int) max > 2) {
max = max / 2;
E++;
}
max = E;
int A = 0, primes[max];
while (prime <= max) {
primes[A] = prime;
A++;
int C = 0;
while (C == 0) {
prime = prime+2;
for (int B = A; B>0; B--) {
if (B == 0) {
C = 1;
else if (prime % primes[b] == 0)
B = 0;
}
}
}
}
int D = 1;
prime = primes[0];
while (num != prime) {
if (num % prime == 0) {
cout << prime << "\n";
num = num / prime;
else
prime = primes[D];
D++;
}
}
cout << prime << "\n";
system ("pause");
return 0;
}
Also the second problem (create a program to give a fibonacci
sequence up to given number) went rather well going to add it in case
anyone has some pointers for me.
#include <iostream>
using namespace std;
int main () {
cout << "This program lists all the numbers in a fibonacci series \n";
cout << "up to a number of your choice. \n" << "Please enter a number? ";
int max;
cin >> max;
int fib =1, preA =0, preB =0;
while (fib <= max) {
cout << fib << "\n";
preB = preA;
preA = fib;
fib = fib+preB;
}
system ("pause");
return 0;
}
Oh and i used system ("pause") because it worked and well cin.get() and such didn't, oh looking back i bet i need to put a variable in the brackets don't I oh well thats what i get for copy/pasting it hehe.