473,407 Members | 2,326 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,407 software developers and data experts.

help with c++ question

can someone gives me tips on how to go about solving this question on main or in privo. stuck :/ Much appreciated

create a program with a loop structure that reads in 2 integers, calculates the sum
of all the integers between these 2 integers (not including these 2 integers) if any, and shows the result. Example, if the 2 integers you read are -2 and 5, then
your program should output 9 (= -1+0+1+2+3+4).
Apr 12 '07 #1
6 1141
gpraghuram
1,275 Expert 1GB
HI,
Check this code

Code removed per Posting Guidelines

Thanks
Raghuram
Apr 12 '07 #2
JosAH
11,448 Expert 8TB
can someone gives me tips on how to go about solving this question on main or in privo. stuck :/ Much appreciated

create a program with a loop structure that reads in 2 integers, calculates the sum
of all the integers between these 2 integers (not including these 2 integers) if any, and shows the result. Example, if the 2 integers you read are -2 and 5, then
your program should output 9 (= -1+0+1+2+3+4).
Take baby steps and try to solve the little steps first:

1) read an integer and assign it to a value.

2) loop from min to max excluding both min and max.

3) add the loop value to a sum variable (which must be initialized to 0).

4) print the sum variable.

Step 1) has to be performed twice for both the min and max values.

kind regards,

Jos
Apr 12 '07 #3
yeah ill give a shot fellas cheers
Apr 12 '07 #4
Savage
1,764 Expert 1GB
HI,
Check this code

Code removed per Posting Guidelines

Thanks
Raghuram
Raghuram was close.Only problem was:

Expand|Select|Wrap|Line Numbers
  1.         for(lnStart=(lnStart+1);lnStart<lnEnd;lnStart++)
  2.         {
  3.             printf("%d\n",lnStart);
  4.         }
This will not print disered result and it will print out all numbers between those
integers.To find the sum you need to insert it inside loop like:

Expand|Select|Wrap|Line Numbers
  1.  
  2.                 int sum=0;
  3.     for(lnStart=(lnStart+1);lnStart<lnEnd;lnStart++)
  4.         {
  5.             printf("%d\n",lnStart);
  6.                                                 sum+=Instart;
  7.  
  8.         }
  9.                                 print sum out............
  10.  

Savage
Apr 12 '07 #5
greetings to savage , Jo , Gp thank you all for the help :)
Apr 12 '07 #6
Savage
1,764 Expert 1GB
greetings to savage , Jo , Gp thank you all for the help :)
Greetings to you lostkid!!!

And it's allways pleasure for us to help!!!!

Regards
Savage
Apr 12 '07 #7

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

Similar topics

1
by: sunaina | last post by:
This is the first program I am writing using PHP and Mysql. I am creating a game where user thinks of an object and my program guesses the object while asking series of yes/no questions. All a...
9
by: sk | last post by:
I have an applicaton in which I collect data for different parameters for a set of devices. The data are entered into a single table, each set of name, value pairs time-stamped and associated with...
1
by: Mohammed Mazid | last post by:
Basically I want to store the answer of a single-choice question (where candidate selects one answer) and multiple-choice question (where candidate selects more than one answer). I would like to...
13
by: Chua Wen Ching | last post by:
Hi there, I saw this article here in vb.net. http://www.error-bank.com/microsoft.public.dotnet.languages.vb.1/148992_Thread.aspx and ...
28
by: Siv | last post by:
Hi, If I run the following: strSQL = "Select * FROM Clients;" da = New OleDb.OleDbDataAdapter(strSQL, Conn) 'Create data adapter cb = New OleDb.OleDbCommandBuilder(da) ...
5
by: Patrick.O.Ige | last post by:
I have an xml and i'm trying to loop each node... When i do FOR EACH i seem not to get my desired result I want to loop through and get only the values that matches the question i specified with...
16
by: pamelafluente | last post by:
I am still working with no success on that client/server problem. I need your help. I will submit simplified versions of my problem so we can see clearly what is going on. My model: A client...
0
by: Mike Collins | last post by:
I someone can please help, I am about at an end in trying to figure this out. I am adding some dynamic controls to my page (I found out that I was supposed to be doing that in the oninit event,...
1
by: TexCube | last post by:
Hello everyone, I have an urgent question. Can data be pulled from an access database table to create a directory that can be printed out and bound together? I need to have each row of a...
3
by: Perry Langla | last post by:
I can not seem to figure this out, please help. This program worked perfectly in Visual Studio 2003. The program gets the information from an Access Database. I am using OleDbSelectCommand to...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.