Bob 15

Okay. Apologies, I must have taken a wrong turn.

Bob 15

On a simple program that any reasonably competent C++ beginner could write? You might find a few people who are interested, but they're all going to be beginners like you who have homework similar to your program's description.

I wish you wouldn't speak for everyone, because you don't. I'm not a beginner, and I'm interested. I contributed to the earlier thread, I respect the OP for coming back with an improved attempt, and in keeping with the spirit of DaniWeb, I'd be more than happy to offer further support with it.

I think you need to adjust your opinion of this program to be more realistic. You're 14 (according to your signature), so it's understandable that you think the world revolves around you and everything that you produce is magic,

Respectfully, I don't think that's called for.

but I'm willing to bet that most of the people who see this program will think the same thing I did. It's quaint, and props to you for doing it, but it's clearly written by a beginner and I could quickly write a better version with minimal effort. Therefore, I have zero interest in either the original program or updates.

Anyone who has no interest in it surely only needs to skip the thread?

If you have any specific questions about how to improve the program, I'll be happy to offer some opinions. However, I'm not going to lavish you with praise, which is clearly what you're expecting by ...

Bob 15

Congratulations on having working code. Are you interested in suggestions for possible improvements?

Bob 15

What part of the task are you having trouble with? Can you write a simple main() function that asks for and stores values for x and n? That'd get you started.

Bob 15

Hi orar,

Looks like you're uncertain about functions at the moment. Here:

void main()
{
    float input();
    float calulate();
    float output();
};

Several problems.

The first is that you should remove the word float from the function call, e.g.

calculate();

The second is that the function is supposed to return a float value, so you need a variable to store the return value:

float value;
value = calculate();

If appropriate, you can combine these and initialise the variable with the return value:

float value = calculate();

The next problem is that the calculate function expects parameters and you're not passing any, e.g.

float inches = 3.1;
float feet = 4.2;
value = calculate(inches,feet);

Next, your calculate function isn't returning the value it's supposed to:

float calculate(float inches, float feet)
{
    float cm;
    float meters;
    cm=2.54*inches;
    meters=feet*.3048;
};

I assume you want to return the calculated value of metres:

float calculate(float inches, float feet)
{
    float cm;
    float meters;
    cm=2.54*inches;
    meters=feet*.3048;

    return meters;
};

Your other functions and function calls have similar problems. These are all pretty fundamental to using functions. Time to dig out your reference book or use Google and read up on functions before going any further.

Good luck with your program.

Bob 15

A long time ago, in a faraway universe, someone who looks like me wrote something called C++ Tutorials for Beginners and Cheapskates, which included a tutorial on loops. It appears there's still a copy collecting dust on the internet, if you think it might help.

https://docs.google.com/viewer?a=v&q=cache:ZPu1hYhBIYcJ:www.mat.unisi.it/personalpages/quaranta/c%2B%2B/C%2B%2B%2520Tutorial.pdf+c%2B%2B+%22beginners+and+cheapskates%22+pdf&hl=en&gl=uk&pid=bl&srcid=ADGEESgF-l4fUa0mkCCwmPDIqdpZX3DcsmCCsPNam-Y4olDP7XHV0m8634-2gLQF7ASchzKWfKBtQqUDEXjpYQwA36yA3zeTM3kTOzyHQcrlng4gUS2OeMfdRtInQ5UCMJIxRf9W-rRN&sig=AHIEtbQ2R2pEFGNeoM_m3hKglbwgPtQqiQ

I haven't read it for years and take no responsibility if following the advice within makes odd things happen while you sleep. And you can safely ignore the URL and email address within the document, they went AWOL a long time ago.

Bob 15

I hope your joking.

You hope my joking what?

The last thing most people need in school, is a professor with a chip on their shoulder.

That's worse than not having a clue? Fine. It's still not a C++ problem.

Bob 15

Do you understand the issues WaltP raised, now? If not, please ask.

Bob 15

I'm glad it's closed.

Bob 15

Need help with this and my professor is teaching way too fast.

I really dont understand any of this and my teacher moves to fast to explain things.

This is not really a C++ issue, it's a problem you have with your professor. Nothing we do or say can fix that. You need to address it with your professor, probably by talking it over first. If that fails, and if you're certain the problem lies with your professor, take it up with the authorities at your school or college.

Bob 15

At this point what you posted won't compile, but the first issue is a simple mismatch between the number of opening and closing braces. Check your charge() function, then see if you can get your code to compile. (There is another problem beyond the braces, but it's probably something you can fix).

Getting what you have to compile is the first step.

Bob 15

You've obviously done quite a lot of work on this already, but I wondered, given that this is C++, whether you'd considered a more object oriented solution (or is that not a possibility for you)?

That aside, and given that you've already implemented a fair amount of this yourself, what exactly is it you need help with?

Bob 15

Hi Nathaliecole,

It's always worth searching DaniWeb to see whether your question has been asked before. I searched on the phrase "number system converter" and it threw up this thread, which may help you to get started:

i would like to create a program that converts a number system to another

http://www.daniweb.com/software-development/cpp/threads/106441/number-system-conversion

If you repeat that search yourself you'll find additional similar threads, some using C, some using Java, but the ideas in those threads may still help you.

Good luck with your program.

Bob 15

In addition to what WaltP said, your compare function isn't working as you expect it to. Take a look at what you're comparing -- DiceTotal and AiDiceTotal -- and check whether this is what you intended.

Bob 15

You're effectively checking that a is equal to b and a is equal to c.

Bob 15

Just double-check your logic with your if-else statements. At the moment it will say all numbers are the same if c is larger than either a or b.

Bob 15

temp.shillings = pe / 12;
temp.pence = pe % 12;

Yeah, does that help? How is your output?

Now imagine that instead of typing 12 or 20 or 240 everywhere within your code, you replaced those literals with a named constant, for example:

const int PENNIES_IN_POUNDS = 240;
const int SHILLINGS_IN_POUNDS = 20;
const int PENNIES_IN_SHILLINGS = 12;

The lines above then become:

temp.shillings = pe / PENNIES_IN_SHILLINGS;
temp.pence = pe % PENNIES_IN_SHILLINGS;

If you go one step further and use a more meaningful name rather than the abbreviation 'pe', you have something like:

temp.shillings = pennies / PENNIES_IN_SHILLINGS;
temp.pence = pennies % PENNIES_IN_SHILLINGS;

You've replaced the magic numbers (12 in this case) with constants with meaningful names (PENNIES_IN_SHILLINGS).

Bob 15

should I do the remainder of both? and not divide.

No, just double check what your expression is for. You're calculating how many shillings there are in a given number of pennies, but you're diving by the number of shillings in a pound (20) rather than how many pennies in a shilling (12) -- even though you correctly use 12 on the next line.

Bob 15

It's surprising how much information an interviewer can obtain even from an incorrect answer.

Bob 15

Footnote: the problem you're seeing is a good example of the type of problem that arises from using magic numbers in your code rather than named constants. If you're not sure what I mean, feel free to ask.

Bob 15

Double-check whether this is doing what you expect it to, keeping in mind how many pennies there are in a shilling.

temp.shillings = pe / 20;
temp.pence = pe % 12;

Bob 15

Here's a thread with a slightly different but related issue here that will probably help (if you scroll down to the bottom):

http://www.daniweb.com/software-development/cpp/threads/22885/1-cin-statementmultiple-values-to-a-vector

Bob 15

Take another look at this line:

cin>>a,b,c;

Double-check how to handle multiple values with cin.

Bob 15

Bob 15

As an aside, C++11 provides an array class which comes with a lot of functionality, if you have a compiler that supports it.

Bob 15

Just a note to add that if the task you've been set is to do this with pointers, you can get rid of integers i and j and does this just through three pointers front, rear and temp.

Bob 15

Here:

*front = entry[i];

this assigns the character at entry[i] to the memory at the address represented by front, but front hasn't been allocated any memory. I suspect what you want is to assign to the pointer the address of the character, like this:

front = &entry[i];

The same applies to the line that follows, with rear.

Watch out also for this:

 while (i != j)

because depending on whether there is an odd or even number of characters i may never equal j.

Bob 15

So,No1 has a clue how to solve the problem?:(

I'm sure that's not the case. What's holding people back is that you're expected to have a go yourself first and so far you haven't made any attempt.

Can you post a link to the website you found the problem on? I'd like to see how the original problem was worded.

Bob 15

What should n be initialized to? Can it be zero? Where do I place the initialation in the program?

It can be initialised to whatever valid value you wish, anywhere prior to first use (currently line 39). What was your intention when you wrote the loop? What purpose is it intended to serve?

Bob 15

warning C4700: uninitialized local variable 'n' used line 39

 32.   int cost[10][10],i,j,k,n,c,visit,visited[10],l,v,count1,vst,p,dup1,dup2;

 39.  for(i=0;i<n;i++)

You're using n in an expression in line 39, for (i=0; i<n; i++), but it hasn't yet been initialised, so it holds an unknown garbage value. When i is compared with n, you're comparing i with whatever garbage value n holds. The compiler, understandably, is warning you of this potential problem, which if unresolved can lead to a bug and possible obscure behaviour.