Having trouble fixing my errors in the code

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 432 Views - Last Post: 31 January 2013 - 01:29 PM Rate Topic: -----

#16 needhelpest  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 12-January 13

Re: Having trouble fixing my errors in the code

Posted 31 January 2013 - 11:03 AM

Courtesy of writing a single sentence and then copypasting it :/
As I fixed it I encountered another problem, when I run the program and it asks me for metres I enter it and then it goes straight to the last else sentence where it displays the correct entered value of P but does not even give me a chance to enter U
Was This Post Helpful? 0
  • +
  • -

#17 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5509
  • View blog
  • Posts: 11,814
  • Joined: 02-June 10

Re: Having trouble fixing my errors in the code

Posted 31 January 2013 - 11:19 AM

I'm going to bow out of the conversation now.

It seems you've stopped debugging your own homework because we're doing it for you.

Nothing you've done or are doing is hard. It just requires you to pay attention and make a little more effort.

Step through your program in the debugger line by line and look at the values of the variables and *think* as to why each if passes or fails. Logic and reasoning skills will take you a long way.



From my FAQ list:

Q: I do x and y happens which I didn't expect but I don't know how to figure out why. How do I debug and find my problem?
A:

This post has been edited by tlhIn`toq: 31 January 2013 - 11:22 AM

Was This Post Helpful? 0
  • +
  • -

#18 needhelpest  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 12-January 13

Re: Having trouble fixing my errors in the code

Posted 31 January 2013 - 11:21 AM

View PosttlhIn`toq, on 31 January 2013 - 11:19 AM, said:

I'm going to bow out of the conversation now.

It seems you've stopped debugging your own homework because we're doing it for you.

Nothing you've done or are doing is hard. It just requires you to pay attention and make a little more effort.

Step through your program in the debugger line by line and look at the values of the variables and *thing* as to why each if passes or fails.



From my FAQ list:

Q: I do x and y happens which I didn't expect but I don't know how to figure out why. How do I debug and find my problem?
A:

I was actually watching these videos as I waited for a reply from the community, I have used do&while earlier for programs with multiple questions. Is that what I should now?
In addition , I use devcpp as it is required by the lecturers of my eCourse.

This post has been edited by needhelpest: 31 January 2013 - 11:24 AM

Was This Post Helpful? 0
  • +
  • -

#19 needhelpest  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 12-January 13

Re: Having trouble fixing my errors in the code

Posted 31 January 2013 - 12:01 PM

Tried using do-while method from my previous experience, the problem remains the same.
Was This Post Helpful? 0
  • +
  • -

#20 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1343
  • View blog
  • Posts: 4,604
  • Joined: 19-February 09

Re: Having trouble fixing my errors in the code

Posted 31 January 2013 - 01:29 PM

This is a common problem for beginners.

26   cin >> P;
  
29   getline(cin, U);



cin >> P; leaves a newline in the input stream.
getline(cin, U); reads the newline as an empty string.

There are various ways of dealing with this such as using the ignore function.

Here though you can just use another cin >>, I think.

26   cin >> P;
     
29   cin >> U;


Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2