473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Loop back to the start of a program?

Expand|Select|Wrap|Line Numbers
  1. #include <StdAfx.h>
  2. #pragma hdrstop
  3. #include <conio.h>
  4. #include <ctype.h>
  5. #include <iostream>
  6.  
  7. //----------------------------------------------------------------------
  8.  
  9. using namespace std;
  10. using std::cout;
  11. using std::endl;
  12. using std::cin;
  13.  
  14. int main ( ) { 
  15. int i;
  16. int x;
  17.  
  18. std::cout << "\n Please enter an even number:";
  19. cin >> x;
  20. if(x%2==1)
  21.         std::cout << "\n Number entered was not even.";
  22.         //This is where i need the loop back to start
  23. else
  24.     std::cout << "\n Number entered was " <<x<< ".";  
  25.     std::cout << "\n\n Next ten even values: ";
  26. for (i=0; i<=8; i++) 
  27. {
  28.      x=x+2;
  29.      std::cout <<x<< " "; 
  30. }
  31. x=x+2;
  32. std::cout <<x<< ".";
  33. getch();
  34. return 0;
  35. }
  36.  
I'll be grateful for any ideas to add to the program. Also, if it helps i'm using Microsoft Visual C++ 2010. The coding i need it to restart the program from the specified point, and if it's possible i'd like to have a y/n option. Thanks :)
Oct 21 '11 #1
3 4186
alexis4
113 100+
I deleted my post because I thought you were asking for something else. The answer was irrelevant. Sorry for that.
Oct 21 '11 #2
whodgson
542 512MB
before line 20 write:
Expand|Select|Wrap|Line Numbers
  1. while(x%2==1){
  2.  
  3. }
Oct 22 '11 #3
no problem thanks anyway alexis
And to solve the problem that when you enter an odd number into the running program it won't show the next ten alternate numbers. But i still need a code to loop back to the start. Anyway, this is the corrected program.
Expand|Select|Wrap|Line Numbers
  1. #include <StdAfx.h>
  2. #pragma hdrstop
  3. #include <conio.h>
  4. #include <ctype.h>
  5. #include <iostream>
  6.  
  7. //----------------------------------------------------------------------
  8.  
  9. using namespace std;
  10. using std::cout;
  11. using std::endl;
  12. using std::cin;
  13.  
  14. int main ( ) { 
  15. int i;
  16. int x; 
  17.  
  18. std::cout << "\n Please enter an even number: ";
  19. cin >> x;
  20. if(x%2==1)
  21.         std::cout << "\n Number entered was not even.";
  22.         //This is where i need the loop back to start
  23.  
  24. if(x%2==0)   
  25.         std::cout << "\n Number entered was " <<x<< ".";  
  26.  
  27. if(x%2==0)
  28.         std::cout << "\n\n Next ten even values: ";
  29.  
  30. if(x%2==0)    
  31.     for (i=0; i<=9; i++) 
  32.     {
  33.         x=x+2;
  34.         std::cout <<x<< " "; 
  35.     }
  36. getch();
  37. return 0;
  38. }
  39.  
Oct 23 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: John Guarnieri | last post by:
I have vb 6 pro and win xp pro, and was looking for some code to add my program to the registry so it will run on windows xp start up, and to also be able to stop it from loading on start up based...
5
by: wavemill | last post by:
Hello! I would like load teh data(it's my program decrypted) in memory and run it directly from my memory. If you have an idea? best regards, wavemill
7
by: Jack Russell | last post by:
Can anyone tell me if there is a .net way of doing these things. I have VB6 code but assume there is a new way. Thanks
6
by: Alexander Widera | last post by:
hello, if i start a program (an exe-file) with Process.Start(...) I don't have the required permissions that the programm needs (i could start the programm but the program needs special rights)....
6
by: Bob Rock | last post by:
Hello, I'm using an executable (for which I do not have the source code nor the pdb file) as the startup application to load a DLL I'm writing and need to debug. If I try to debug the DLL I...
1
markmcgookin
by: markmcgookin | last post by:
Hi Folks, this is a problem I had a few days ago, and I was able to solve it, but I thought I'd post the solution I found here incase anyone has a similar problem! I found this stuff on an MSNDN...
2
by: Tim Kelley | last post by:
I have an application that I have distributed using one click install. I selected the option to allow the program to be run if the server is offline. From another program I want to be able to...
2
Lookin4Toons
by: Lookin4Toons | last post by:
Trying to create a text box w/user input to enter a suggested user name and query AD to see if the name is available. This is for HR users who do not have access to the Admin tools to open the...
1
by: hopes | last post by:
excuse me, simple question I want a user to enter a string so that I may recursively call it to reverse it. Just one thing, i wanna make sure the user did not enter a carriage return, if he/she...
2
by: John Hutchison | last post by:
Hey everybody, this is my first post, so I hope I'm doing this right. I'm just starting to learn how to program, so I'm sorry if my error is obvious, but I can't seem to find the answer. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.