K so I'v been trying for the past four days to sort this program out, i'll admit i'm not particularly good at programming, i'm really new at it and I'm struggling through my uni course, i've written as much of this program as i can but i don't know what to do next.
Here's what i'v got
#include <iostream>
#include <cmath>
using namespace std;
// The precondition statement indicates what
// must be true before the function is called.
// The postcondition statement indicates what
// will be true when the function finishes its work.
int largest_prime_factor (int a);
// precondition: a > 0
// postcondition: the function returns to the largest prime factor of a
int squared_digit_length (int a);
// precondition: a > 0
// postcondition: the function returns to the square digit length starting from a
// define other functions if necessary
int main ()
{
char ch1, ch2; // ch1 is used for the first letter of the first name
// ch2 is used for the first letter of the surname
int n1, n2, n3, n4, n5; // used for the 5 steps of the task
cout << "Enter your first name and surname: " << flush;
cin >> ch1; // read the first letter of the first name
cin.ignore(100,' '); // ignore the rest of the character in the first name
cin >> ch2; // read the first letter of the surname
n1 = static_cast<int>(ch1);
n2 = static_cast<int>(ch2);
n3= squared_digit_length(n1);
n4 = squared_digit_length(n2);
n5 = n4 + n5;
cout << n1 << n2 << endl;
return 0;
}
int square_digit_length(int a)
{
int ones, tens, hundreds;
float floatOnes, floatTens, floatHundreds;
int num = 0;
int a;
while (a = 4)
{
if (a >= 100)
tens = (a/100)%10;
else tens = a/10;
ones = a%10;
hundreds = a/100;
floatOnes = pow((float)ones,2);
floatTens = pow((float)tens,2);
floatHundreds = pow ((float)hundreds,2);
num++;
a= (floatOnes+floatTens+floatHundreds);
}
}
basically the program has to take in a first and last name, convert the first letters of the name into thier ASCII values, calculate the squared digit length of both letters, then output those lengths and the largets prime factor of those lenghts added together.
I know i need to use return functions but i don't really understand how they work and i need a function for the largest prime factor.
i'd really apreciate it if anyone could help, and would love it if people could explain their suggestions so that i actually learn something from it. Thanx C:
Bookmarks