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

Three simple c++ exercises

Create a C++ console application that uses a while loop to count, total, and average a series of positive integers entered by a user. The user enters a –1 to signal the end of data input and to display the count, total, and average of the numbers entered.

The pseudocode for the program is:

Start

Enter user's input

Begin Loop

While user's input is greater than sentinel

increment counter

add user's input to the sum

Enter user's input again

End Loop

Display messages

Stop







Exercise 2:


Write a program that uses at least one for loop to print a section of the multiplication table. The user should be able to specify the section of the table to be displayed. The program will also display a count of the number of rows printed, the count of the columns printed and the sum of all calculated values.

The user input will appear as such:

**Create a Multiplication Table**
Enter the starting value: 2
Enter the ending value: 5

The pseudocode for the program is:

Start

Enter user's Table dimension (start and end number)

Begin For Loop (colnum = startnumber, colnum<=endnumber, increment colnum)

display colnum

increment colnum

End For loop

initialize currentRow as startnumber

Begin while loop (until curentRow is less than or equal to endnumber)

display currentRow

increment Rowcount

Begin For Loop (colnum = startnumber, colnum<=endnumber, increment colnum)

display product of colnum and currentRow

Add the product of colnum and currentRow to the sum

End For Loop

increment currentRow

End of While Loop

Display row, col and sum printed

Stop


The output will be:

X 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25



rows printed = 4
Columns printed = 4
Sum: 196


Exercise 3, last one

Create a C++ console application that generates a random number that must be guessed by a user. The program will indicate to the user if their guess is correct, too high or too low. It will also report the number of guesses the user has made. The game ends when the user enters a negative one (-1) or has guessed the number. The program should include a do while loop, decision statements, constants and variables.

The pseudocode for the program is:

Start
Generate a random number

Begin loop
Enter user's guess
If guess is right
Display message and exit loop
If guess is high
Display message
If guess is low display message
Display message
Increment counter
End loop

Display number of guesses
Stop


When the program is executed it will produce the following output:

**The Guessing Game**

Enter a Guess (-1 to exit):

After the user makes a guess the program will output one of these statements:

Too High, Try Again!
Too Low, Try Again!
You’ve guessed wisely!
After a correct guess or the user ends execution the program will output one of these statements:

The number was X it took you X guesses.
The number was X you gave up after X guesses.
Nov 8 '09 #1
5 9330
weaknessforcats
9,208 Expert Mod 8TB
No one is going to write your code for you.

If you have a specific question, then you will receive assistance.

Post again when you have got some of this coded and are still stuck.
Nov 8 '09 #2
this is my third week in learning c++ and i do not know where to start
Nov 8 '09 #3
newb16
687 512MB
3 weeks is quite enough to master all language constructions required for such tasks. If they were not explained to you, start with googling for 'c++ loop example'
Nov 8 '09 #4
for the second exercise i am very confused as it seems there are three loops total required and way too many variables to be initilized. this is what i came up with, can someone please help me find out what i did wrong?

Expand|Select|Wrap|Line Numbers
  1. //create a multiplication table
  2. #include <iostream>
  3. # include <iomanip>
  4. using namespace std;
  5.  
  6. int main()
  7. int startValue, int endValue, int currentCol, int currentRow;
  8. for(currentCol=startValue, currentCol<=endValue,startValue++);
  9. cout<<" the column is : " << currentCol<< endl;
  10. }
  11. while(currentRow <=endValue);
  12. cout<<" the current row is :" << currentRow<< endl;
  13. cout << currentRow ++;
  14.  
that is all i got can you please test what you have before so i ll know what i did wrong? i appreciate any help as you can see i need it bad :(
Nov 10 '09 #5
newb16
687 512MB
It doesn't even compile - variable declaration is wrong, 'for' loop syntax is wrong.
Semicolon after 'for' should not be there. While loop appears afer closing brace of main function.
Nov 10 '09 #6

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

Similar topics

4
by: Gordon | last post by:
Hi, I was wondering if someone could point me in the direction of some online exercises to help me learn to program (in Python). I'm currently working through Magnus Hetland's Practical...
8
by: Wous Mant | last post by:
Hello, I am a student in an university and studying C++.Final exams are coming.I'd like to solve as much exercises as possible.I'd like you to test myself with different kind of exercises.Do you...
1
by: Zachary Turner | last post by:
I am just learning the syntax of C#, and I want some "exercise" type ideas to allow me to test various features of the language. I don't really want to resort to a "Teach Yourself C#" type of book...
0
by: Ben Edwards (lists) | last post by:
Have been working through Dive Into Python which is excellent. My only problem is that there are not exercises. I find exercises are a great way of helping stuff sink in and verifying my...
0
by: tjsailor | last post by:
I'm recently reading this book, and I really think exercises in this book is rather good, but from nowhere can I get the solutions to the exercises, can anybody share his or her if he or she got...
8
by: jopy887 | last post by:
Hey people, Does someone know a good site for C exercises? For beginners.. Jonathan
176
by: nw | last post by:
Hi, I previously asked for suggestions on teaching testing in C++. Based on some of the replies I received I decided that best way to proceed would be to teach the students how they might write...
5
by: Martin | last post by:
I am trying to improve my Python skills through some exercises. Currently I am working on Larry's "15 exercises to know a programming language " (http://www.knowing.net/...
2
by: TSB | last post by:
Currently I am reading Sam's Teach Yourself PHP in 24 Hours. The book is very good, but it is extremely slim on exercises. I'm one of those types of people who learn by doing, not by reading or...
1
by: TheTamdino | last post by:
I am currently reading Beginning PHP and MySQL 5: From Novice to Professional, Second Edition by W. Jason Gilmore. This is an excellent book, but it has no exercises in it. I'm the kind of person...
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: 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
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
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,...

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.