How do I return to a specific point in main if user input wrong data.

+2 Number Double07 · February 21, 2015
Okay, so I know that if I put return main ( ) in my main function, it will return to the start of the main.  How do I return to a specific line of code and retain the information previously entered?  In my code, I ask the user three things, but in the second question, they must enter a value between 0 or 1 (float) or they need to enter the value again.

int main()
    Newspaper tNewspaper;

    cout tNewspaper.Ads_Shown;

    cout tNewspaper.Percentage_User_Ads;

    if (tNewspaper.Percentage_User_Ads > 1.0000000)
        if (tNewspaper.Percentage_User_Ads < 0.0000000)

Post a Reply


- page 2
Oldest  Newest  Rating
0 Number Double07 · February 28, 2015
I see how it can be considered bad practice to use the goto.  It works here, but mainly because I am being careful about it's use.  But, I can see how it could lead to problems.  Imagine if I jumped from thebeginning of my code to somewhere in the middle.  I could miss many things in between easily.  Debugging would be messy.  I could miss variable declarations, all sort of nasty things.   It would be even more confusing the more gotos I used.  Lots of jumping, would make debugging a nightmare.
0 Number Double07 · March 10, 2015
Actually, the goto statement worked for me.  I got it to do what I wanted using the goto and it was really very simple; I just had to get around some scope issues.
0 Abdullah Nauman · March 10, 2015
If the code works its fine
  • 1
  • 2



Used in many types of software including music players, video games, and many large scale applications.

Bucky Roberts Administrator