computer science C++ questions

computer science C++ questions

Posted in the Computer Science Forum

Andrew Gargani

Odessa, TX

#1 Sep 14, 2008
Given that two int variables, total and amount , have been declared, write a sequence of statements that:
initializes total to 0
reads three values into amount , one at a time.

After each value is read in to amount , it is added to the value in total (that is, total is incremented by the value in amount ).

Instructor's notes: If you use a loop, it must be a for loop.
And if you use a loop control variable for counting, you must declare it.
Andrew Gargani

Odessa, TX

#2 Sep 14, 2008
Given that two int variables, total and amount, have been declared, write a loop that reads integers into amount and adds all the non-negative values into total. The loop terminates when a value less than 0 is read into amount. Don't forget to initialize total to 0.


Instructor's notes: This problem requires either a while or a do-while loop.
Andrew Gargani

Odessa, TX

#3 Sep 14, 2008
Given an int variable n that has already been declared and initialized to a positive value, and another int variable j that has already been declared, use a do...while loop to print a single line consisting of n asterisks. Thus if n contains 5, five asterisks will be printed. Use no variables other than n and j .
Andrew Gargani

Odessa, TX

#4 Sep 14, 2008
Given an int variable n that has been initialized to a positive value and, in addition, int variables k and total that have already been declared, use a do...while loop to compute the sum of the cubes of the first n whole numbers, and store this value in total . Thus if n equals 4, your code should put 1*1*1 + 2*2*2 + 3*3*3 + 4*4*4 into total . Use no variables other than n , k , and total .
TALK 2 EXPERTS

Toronto, Canada

#5 May 31, 2011
TALK 2 EXPERTS

C, C ++, C# forums:
http://www.c.talk2experts.com
.

Tell me when this thread is updated:

Subscribe Now Add to my Tracker

Add your comments below

Characters left: 4000

Please note by submitting this form you acknowledge that you have read the Terms of Service and the comment you are posting is in compliance with such terms. Be polite. Inappropriate posts may be removed by the moderator. Send us your feedback.

Computer Science Discussions

Title Updated Last By Comments
News A Cloud for the Artificial Mind: This Data Cent... Feb 7 thumper0755 1
CS Thesis Topics (Nov '08) Feb 7 laila 110
News UK pardons thousands convicted under past anti-... Jan 31 Phyllis Schlafly ... 1
News What is going on at the Washington Post? Jan 25 a person who can ... 6
News When computers were human: the black women behi... Jan 22 Ms Mack 3
News Why Instagram Won 2016 and Snapchat Didn't Jan '17 Mos-A 1
News Recounts or no, US elections are still vulnerab... Dec '16 RustyS 28
More from around the web