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

Conditional Statement: Nested If

Write a program that will identify odd and even number. If the number is odd multiply it by 3, otherwise add it by 10.
Jan 30 '14 #1
2 1100
Expand|Select|Wrap|Line Numbers
  1. Console.Write("Enter Number: ");
  2.             int n = int.Parse(Console.ReadLine());
  3.             while (n > 0)
  4.             {
  5.                 if ((n % 2) == 0)
  6.                 {
  7.                     Console.WriteLine("\nThe Number is Even\n");
  8.                     Console.WriteLine("Hence the result is :{0}", n + 10);
  9.                 }
  10.                 else
  11.                 {
  12.                     Console.WriteLine("\nThe Number is Odd\n");
  13.                     Console.WriteLine("Hence the result is :{0}", n * 3);
  14.                 }
  15.             }
Jan 30 '14 #2
weaknessforcats
9,208 Expert Mod 8TB
It doesn't look like n is actually getting changed.
Jan 30 '14 #3

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

Similar topics

7
by: Shaldaman | last post by:
I have an Access form called "Login". "Command10" is a button on the form and "Text5" is a text field on it. When a user enters a value in the Text5 text field and clicks the button Command10, I...
8
by: arganx | last post by:
The conditional statement "if(j.... always executes regardless of what you enter. BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam) { char buffer=""; GetWindowText(hwnd,buffer,256);...
5
by: Gary Wessle | last post by:
Hi if I have a method like this bool myClass::myMothod(myType& mt, herType ht) throw ( SomeExp ); how can I use it in a conditional statement if ( try {
43
by: dev_cool | last post by:
Hello friends, I'm a beginner in C programming. One of my friends asked me to write a program in C.The purpose of the program is print 1 to n without any conditional statement, loop or jump. ...
5
by: bamn68 | last post by:
how do i use conditional statement in sql? im using access 2003 as frontend and backend. What would be the SQL statement for the situation below? I would like to count the number of records in...
0
by: cljordan | last post by:
I am trying to create a database that list materials and their quantities, and highlights quantities that come up outside a certain percentage range against the average. I have tried the following...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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.