473,396 Members | 1,785 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,396 software developers and data experts.

Going Crazy Over Program

okay here is the task I must do...but I can't do it for the life of me...can any one of you figure this code out and show it to me?



3. Modify the above program, so that if the number entered is lower than 10 a message, "That number is lower than 10" is printed. If the number entered is equal to 10, a message, "That number is equal to 10" is printed . If the number entered is higher than 10, a message "That number is valid" followed by the message "Done" is printed. You will need to use a while loop as well as an if-else statement.

Sample input and output :
Enter a number larger than 10 : 5
That number is lower than 10
Enter a number larger than 10 : 10
That number is equal to 10
Enter a number larger than 10 : 15
That number is valid
Done
Jul 31 '07 #1
8 1372
r035198x
13,262 8TB
okay here is the task I must do...but I can't do it for the life of me...can any one of you figure this code out and show it to me?



3. Modify the above program, so that if the number entered is lower than 10 a message, "That number is lower than 10" is printed. If the number entered is equal to 10, a message, "That number is equal to 10" is printed . If the number entered is higher than 10, a message "That number is valid" followed by the message "Done" is printed. You will need to use a while loop as well as an if-else statement.

Sample input and output :
Enter a number larger than 10 : 5
That number is lower than 10
Enter a number larger than 10 : 10
That number is equal to 10
Enter a number larger than 10 : 15
That number is valid
Done
Please read the posting guidelines. It's very easy to get help here if you follow them.
Jul 31 '07 #2
seforo
60
where do you get stuck? Read posting guidelines for this site please
Jul 31 '07 #3
Okay sorry...well the problem right now with my program is at random times (depending on the number I use) it will finish the program. The code looks okay but obviously is not...I'm fairly new to C++ and am not sure if my While loop is correct:

cout << "Enter a number greater than 10: ";
cin >> integer;
while (integer == 10) {
cout << "That number is equal to ten" << endl;
cout << "Enter a number greater than 10: ";
cin >> integer;

And if my if else statement is either:

cout << "Enter a number greater than 10: ";
cin >> integer;
if (integer < 10)
{
cout << "That number is too small" << endl;
cout << "Enter a number greater than 10: ";
cin >> integer;
}
else
{
cin >> integer;

That is the whole of my code...except the if else comes before the while.
Jul 31 '07 #4
r035198x
13,262 8TB
Okay sorry...well the problem right now with my program is at random times (depending on the number I use) it will finish the program. The code looks okay but obviously is not...I'm fairly new to C++ and am not sure if my While loop is correct:

cout << "Enter a number greater than 10: ";
cin >> integer;
while (integer == 10) {
cout << "That number is equal to ten" << endl;
cout << "Enter a number greater than 10: ";
cin >> integer;

And if my if else statement is either:

cout << "Enter a number greater than 10: ";
cin >> integer;
if (integer < 10)
{
cout << "That number is too small" << endl;
cout << "Enter a number greater than 10: ";
cin >> integer;
}
else
{
cin >> integer;

That is the whole of my code...except the if else comes before the while.
Please use code tags when posting code.
You need to keep taking in input until the number is greater than 10 so the
Expand|Select|Wrap|Line Numbers
  1.  cout << "Enter a number greater than 10: ";
  2.               cin >> integer;
Should go into the while
Expand|Select|Wrap|Line Numbers
  1. int number = 0;
  2. while(number < 10) {
  3.      cout << "Enter a number greater than 10: ";
  4.                    cin >> number;
  5.     //your if-else go here
  6. }
Jul 31 '07 #5
seforo
60
Learn a proper use of while loop, also learn who to use break and continue statements. I have modified your code alittle bit
Expand|Select|Wrap|Line Numbers
  1.   cout << "Enter a number greater than 10: ";
  2.   while (true) {    
  3.     cin >> integer;    
  4.     if(integer==10)
  5.       {
  6.     cout << "That number is equal to ten" << endl;
  7.     cout << "Enter a number greater than 10: ";
  8.       }
  9.     else if(integer < 10)
  10.       {
  11.     cout << "That number is too small" << endl;
  12.     cout << "Enter a number greater than 10: ";
  13.       }
  14.     else 
  15.       {
  16.     cout<<"That Number is valid"<<endl;
  17.         cout<<"Done"<<endl;
  18.     break;
  19.       }
  20.   }
  21.  
Jul 31 '07 #6
r035198x
13,262 8TB
Learn a proper use of while loop, also learn who to use break and continue statements. I have modified your code alittle bit
Expand|Select|Wrap|Line Numbers
  1.   cout << "Enter a number greater than 10: ";
  2.   while (true) {    
  3.     cin >> integer;    
  4.     if(integer==10)
  5.       {
  6.     cout << "That number is equal to ten" << endl;
  7.     cout << "Enter a number greater than 10: ";
  8.       }
  9.     else if(integer < 10)
  10.       {
  11.     cout << "That number is too small" << endl;
  12.     cout << "Enter a number greater than 10: ";
  13.       }
  14.     else 
  15.       {
  16.     cout<<"That Number is valid"<<endl;
  17.         cout<<"Done"<<endl;
  18.     break;
  19.       }
  20.   }
  21.  
Compare the structure of your solution to mine.
Generally avoid the while(true) construct if you can.
Jul 31 '07 #7
Please use code tags when posting code.
You need to keep taking in input until the number is greater than 10 so the
Expand|Select|Wrap|Line Numbers
  1.  cout << "Enter a number greater than 10: ";
  2.               cin >> integer;
Should go into the while
Expand|Select|Wrap|Line Numbers
  1. int number = 0;
  2. while(number < 10) {
  3.      cout << "Enter a number greater than 10: ";
  4.                    cin >> number;
  5.     //your if-else go here
  6. }
Okay I did this...it seemed to work for not stopping when I put a smaller number or the same...but when I put a bigger number it didn't work...will keep trying things but like I said I'm new to C++...but this was great, thanks for the help
Jul 31 '07 #8
r035198x
13,262 8TB
Okay I did this...it seemed to work for not stopping when I put a smaller number or the same...but when I put a bigger number it didn't work...will keep trying things but like I said I'm new to C++...but this was great, thanks for the help
Keeping trying things is the way to go. Only post when you're sure you've tried the best you can and help will always be available.
Jul 31 '07 #9

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

Similar topics

1
by: Richard | last post by:
I need help. I have a smarty based program that I am modifying. I have a smarty template file that consists of smarty and HTML. I need to integrate some PHP database calls into it. My problem...
81
by: julio | last post by:
Sorry but there is no another way, c# .net and mono are going to rip python, not because python is a bad lenguage, but because is to darn old and it refuses to innovate things, to fix wrong things,...
5
by: spoilsport | last post by:
Ive got to write a multi-function program and I'm plugging in the functions but I keep getting this error from line 40. Im new to this and cant find an answer anywhere. Sam #include...
3
by: alef | last post by:
Hi, I have the following code which is driving me crazy. I compile it on MacOSX and it keeps crashing upon entering a command in the program (ran trough gdb) pwd Program received signal...
4
by: ifmusic | last post by:
i have this sort of server - client (which is described as servents in the gnutella specification, and it's what i'm trying to do..) And this is what happens: SOMETIMES, when computer A sends...
1
by: Zack | last post by:
I am writing an app using FileSystemWatcher and just went a little class crazy. I have the following classes Server MasterServer inherits server SlaveServer inherits server SiblingServer...
6
by: thomas.luce | last post by:
Okay, I have been programming for a long time, and am getting back into C after about a 4 year break from it. Below is some code that won't compile for the life of me, and it is driving me crazy!...
3
by: Bob Bedford | last post by:
I understand nothing about the rights ! I create directories and subdirs by php scripts. I've an admin accound, and trying to delete files by FTP, I've not the right to. Admin should have ALL...
28
by: onkar | last post by:
This idea might be vey crazy. But I hope to get answers to this .. from comp.lang.c If a compiler is designed such that it automatically adds a free() matching every malloc() then is it not a...
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: 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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.