Programming

Programming Questions? Ask a Programmer for Answers ASAP

Ask a Computer Expert,
Get an Answer ASAP!

Programming

Write A Program Using While Loop using C++

Customer Question
Write a program that uses...

Write a program that uses while loops to perform the following steps: 1. prompt the user to enter 2 integers firstNUm and secondNum (firstNum must be less than secondNum).

2. Output all odd numbers between firstNum and secondNum.

3. Output the sum of all even numbers between firstNum and secondNum.

4. Output the numbers and their squares between 1 and 10.

5. Output the sum of the square of the odd numbers between firstNum and secondNum.

6. Output all uppercase letters.

Submitted: 8 years ago.Category: Programming
Show More
Show Less
Ask Your Own Programming Question
Answered in 1 hour by:
4/28/2009
Programmer: Steve Bradford, Computer Software Engineer replied 8 years ago
Steve Bradford
Steve Bradford, Computer Software Engineer
Category: Programming
Satisfied Customers: 47
Experience: B.S. in Computer Science. Years of software and database development in several languages.
Verified

Here you go I treated between as inclusive. Thanks.

#include "conio.h"

#include

#include

using namespace std;

int main()

{

int firstnum, secondnum;

firstnum = 0;

secondnum = 0;

while (firstnum >= secondnum) //get the first and second number until they are correct

{

cout << "PLEASE ENTER THE FIRST NUMBER: ";

cin >> firstnum;

cout << endl << "PLEASE ENTER THE SECOND NUMBER:";

cin >> secondnum;

cout << endl;

if (firstnum >= secondnum)

{

cout << "THE FIRST NUMBER MUST BE LESS THAN THE SECOND NUMBER. PLEASE TRY AGAIN." << endl << endl;

}

}

int i = firstnum;

int evensum = 0;

int oddsum = 0;

cout << endl << "ODD NUMBERS BETWEEN " << firstnum << " AND " << secondnum << endl;

while (i <= secondnum)

{

if (i%2 == 0) //even, take sum

{

evensum += i;

}

else //odd,

{

cout << i << endl;

oddsum += i;

}

i++;

}

cout << endl << "SUM OF EVEN NUMBERS BETWEEN " << firstnum << " AND " << secondnum << ": ";

cout << evensum << endl;

i = firstnum;

cout << endl << "THE SQUARES OF THE NUMBERS BETWEEN 1 AND 10: " << endl; // I am assuming this is the numbers between 1 and 10 and firstnumber and second number

while (i <= secondnum)

{

if (i<=10)

{

cout << i << ": " << (i * i) << endl;

}

i++;

}

cout << endl << "SUM OF ODD NUMBERS BETWEEN " << firstnum << " AND " << secondnum << ": ";

cout << oddsum << endl << endl;

cout << "PRESS ANY KEY TO EXIT...";

_getch();

return 0;

}

Ask Your Own Programming Question
Customer reply replied 8 years ago
Hi Steve I noticed at the top of the code you have #include "conio.h" Can I delete this or is it needed for this progra,m because I never seen that before and my professor will question that. Also what is the -getch(); That has to do with the uppercase letters? PLease let me know. Thank you.
Programmer: Steve Bradford, Computer Software Engineer replied 8 years ago
The conio.h is the library for the _getch function. I just used it for the "PRESS ANY KEY TO EXIT..." ability so you could see the output before the window closes. If you run it without that the program will run and exit (closing the console window) without you being able to see the results.
Ask Your Own Programming Question
Ask Steve Bradford Your Own Question
Steve Bradford
Steve Bradford
Steve Bradford, Computer Software Engineer
Category: Programming
Satisfied Customers: 47
47 Satisfied Customers
Experience: B.S. in Computer Science. Years of software and database development in several languages.

Steve Bradford is online now

A new question is answered every 9 seconds

How JustAnswer works:

  • Ask an ExpertExperts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional AnswerVia email, text message, or notification as you wait on our site. Ask follow up questions if you need to.
  • 100% Satisfaction GuaranteeRate the answer you receive.

JustAnswer in the News:

Ask-a-doc Web sites: If you've got a quick question, you can try to get an answer from sites that say they have various specialists on hand to give quick answers... Justanswer.com.
JustAnswer.com...has seen a spike since October in legal questions from readers about layoffs, unemployment and severance.
Web sites like justanswer.com/legal
...leave nothing to chance.
Traffic on JustAnswer rose 14 percent...and had nearly 400,000 page views in 30 days...inquiries related to stress, high blood pressure, drinking and heart pain jumped 33 percent.
Tory Johnson, GMA Workplace Contributor, discusses work-from-home jobs, such as JustAnswer in which verified Experts answer people’s questions.
I will tell you that...the things you have to go through to be an Expert are quite rigorous.

What Customers are Saying:

My Expert answered my question promptly and he resolved the issue totally. This is a great service. I am so glad I found it I will definitely use the service again if needed.

One Happy CustomerNew York

Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help.

Mary C.Freshfield, Liverpool, UK

This expert is wonderful. They truly know what they are talking about, and they actually care about you. They really helped put my nerves at ease. Thank you so much!!!!

AlexLos Angeles, CA

Thank you for all your help. It is nice to know that this service is here for people like myself, who need answers fast and are not sure who to consult.

GPHesperia, CA

I couldn't be more satisfied! This is the site I will always come to when I need a second opinion.

JustinKernersville, NC

Just let me say that this encounter has been entirely professional and most helpful. I liked that I could ask additional questions and get answered in a very short turn around.

EstherWoodstock, NY

Thank you so much for taking your time and knowledge to support my concerns. Not only did you answer my questions, you even took it a step further with replying with more pertinent information I needed to know.

RobinElkton, Maryland

< Previous | Next >

Meet the Experts:

ATLPROG

ATLPROG

Computer Software Engineer

7,677 satisfied customers

MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML

LogicPro

LogicPro

Computer Software Engineer

7,109 satisfied customers

Expert in C, C++, Java, DOT NET, Python, HTML, Javascript, Design.

unvadim

unvadim

Computer Software Engineer

1,168 satisfied customers

Good knowledge of OOP principles. 3+ years of programming experience with Java and C++. Sun Certified Java Programmer 5.0.

lifesaver

lifesaver

Computer Software Engineer

950 satisfied customers

Several years of intensive programming and application development experience in various platforms.

ehabtutor

ehabtutor

Computer Software Engineer

936 satisfied customers

Bachelor of computer science, 5+ years experience in software development, software company owner

TheDoctor

TheDoctor

Software Engineer

893 satisfied customers

M.S. in Internet Information Systems

The-PC-Guy

The-PC-Guy

Software Engineer

789 satisfied customers

Extensive Knowledge in PHP, MYSQL, CSS & Javascript

< Previous | Next >

Related Programming Questions
Create a Visual Logic® program that will: • Create an array
Create a Visual Logic® program that will: • Create an array of people's first names. Using a loop, read the names from a text (.txt) file, and store each one into the array. The array should allow for… read more
LogicPro
LogicPro
Computer Software Engineer
Bachelor of Technology
7,109 satisfied customers
I got some problem on my poker hand program homework, C C++,
Hi! I got some problem on my poker hand program homework … read more
LogicPro
LogicPro
Computer Software Engineer
Bachelor of Technology
7,109 satisfied customers
Python, "-"-"-"-" \ \ / / \ \ / / \ \ "-"-"-"-" no
quot;-"-"-"-" \ \ / / \ \ / / \ \ "-"-"-"-" JA: What programs and versions are you using? Customer: Python JA: What is your ideal outcome? How can we solve this for you? Customer: "-"-"-"-" \ \ / / \ … read more
LogicPro
LogicPro
Computer Software Engineer
Bachelor of Technology
7,109 satisfied customers
I'm looking to hire someone to make a buzzfeed question
Hello, I'm looking to hire someone to make a buzzfeed question styled game in Python. … read more
LogicPro
LogicPro
Computer Software Engineer
Bachelor of Technology
7,109 satisfied customers
I have a wordpress site with go daddy and all the content
I have a wordpress site with go daddy and all the content and layout is gone I just got off the phone with godaddy and then said my site IP address was changed somehow and they just changed it back bu… read more
Jinsmn
Jinsmn
Systems Administrator
Diplom
1,260 satisfied customers
In this lab you will gain experience using all the concepts
In this lab you will gain experience using all the concepts we learned to this point, which include classes, methods, collections, and file input/output. Also, you will gain experience in team program… read more
LogicPro
LogicPro
Computer Software Engineer
Bachelor of Technology
7,109 satisfied customers
For LogicPro Only" The __________ keyword allows the
quot;For LogicPro Only" The __________ keyword allows the programmer to declare a set of constant values represented by identifiers.A. ref B. out C. enum D. returnPreceding a parameter with the ______… read more
LogicPro
LogicPro
Computer Software Engineer
Bachelor of Technology
7,109 satisfied customers
A magic square Customer Question A magic square is a 2-D
A magic square Customer Question A magic square is a 2-D list where the sum of each row is equal to the sum of each column and is equal to the sum of each of the two diagonals. Here is an example of a… read more
LogicPro
LogicPro
Computer Software Engineer
Bachelor of Technology
7,109 satisfied customers
I'm fairly new to programming and have been working on the
Hi, I'm fairly new to programming and have been working on the following array loop and I'm stuck on refactoring a for loop into a while loop: //write a for loop that takes each number, multiplies it … read more
LogicPro
LogicPro
Computer Software Engineer
Bachelor of Technology
7,109 satisfied customers
Assignment 3 Please start with this source code. Write a
Assignment 3 Please start with this source code.Write a program that opens the following text file and processes it contents. The program should display the following per store: The total sales for ea… read more
LogicPro
LogicPro
Computer Software Engineer
Bachelor of Technology
7,109 satisfied customers
How do I get to calculates the total annual compensation of
How do I get to calculates the total annual compensation of the salesperson … read more
George Sibiya
George Sibiya
PhD
194 satisfied customers
I have a php yii application currently running on a server
I have a php yii application currently running on a server that I'd like to bring down to my computer. I started by installing yii on my mac computer by following this documentation (http://www.yiifra… read more
George Sibiya
George Sibiya
PhD
194 satisfied customers
You will need to create a console-based application whose
You will need to create a console-based application whose Main() method accepts ten integer values from the user and stores them in an array. Next, create a method that determines and displays the sma… read more
LogicPro
LogicPro
Computer Software Engineer
Bachelor of Technology
7,109 satisfied customers
OKPR1015211 POSTANSWER I have a .net software question. In
OKPR1015211 POSTANSWER I have a .net software question. In my .cs file I have commented out all the messages but when there is a error with the database connection I get a messagebox and it stops the … read more
Chris Baxter
Chris Baxter
28 satisfied customers
Need help with a WordPress plugin, "Subscribe to Comments
Need help with a WordPress plugin, "Subscribe to Comments Reloaded". It doesn't send any email messages.… read more
Jinsmn
Jinsmn
Systems Administrator
Diplom
1,260 satisfied customers
Assignment3_1.java - Write a console (all I/O via System.in
Assignment3_1.java - Write a console (all I/O via System.in and System.out) program that reads in two integer numbers and identifies if their sum is at least 3 times greater than their product. Print … read more
LogicPro
LogicPro
Computer Software Engineer
Bachelor of Technology
7,109 satisfied customers
Write a console program (java) that:  Uses a while loop to
Write a console program (java) that: Uses a while loop to perform the following steps: 1. Prompt the user to input two integers: firstNum and secondNum where secondNum is at least 10 greater than fir… read more
LogicPro
LogicPro
Computer Software Engineer
Bachelor of Technology
7,109 satisfied customers
Write a console program that repeatedly prompts the user to
Write a console program that repeatedly prompts the user to enter data until they type done (any case, Upper, Lower, or Mixed). As they enter the data, assign it to a two-dimension array where the fir… read more
LogicPro
LogicPro
Computer Software Engineer
Bachelor of Technology
7,109 satisfied customers
Disclaimer: Information in questions, answers, and other posts on this site ("Posts") comes from individual users, not JustAnswer; JustAnswer is not responsible for Posts. Posts are for general information, are not intended to substitute for informed professional advice (medical, legal, veterinary, financial, etc.), or to establish a professional-client relationship. The site and services are provided "as is" with no warranty or representations by JustAnswer regarding the qualifications of Experts. To see what credentials have been verified by a third-party service, please click on the "Verified" symbol in some Experts' profiles. JustAnswer is not intended or designed for EMERGENCY questions which should be directed immediately by telephone or in-person to qualified professionals.

Disclaimer: Information in questions, answers, and other posts on this site ("Posts") comes from individual users, not JustAnswer; JustAnswer is not responsible for Posts. Posts are for general information, are not intended to substitute for informed professional advice (medical, legal, veterinary, financial, etc.), or to establish a professional-client relationship. The site and services are provided "as is" with no warranty or representations by JustAnswer regarding the qualifications of Experts. To see what credentials have been verified by a third-party service, please click on the "Verified" symbol in some Experts' profiles. JustAnswer is not intended or designed for EMERGENCY questions which should be directed immediately by telephone or in-person to qualified professionals.

Show MoreShow Less

Ask Your Question

x