473,853 Members | 1,839 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Three simple c++ exercises

5 New Member
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<=endnumb er, 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<=endnumb er, 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 9373
weaknessforcats
9,208 Recognized Expert Moderator Expert
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
just curious
5 New Member
this is my third week in learning c++ and i do not know where to start
Nov 8 '09 #3
newb16
687 Contributor
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
just curious
5 New Member
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 Contributor
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
10400
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 Python, which doesn't have any exercises/problem sets (for the beginning chapters on things like string manipulation etc). I'd rather not get another book. Cheers,
8
5448
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 know any website where there are exercises with solutions so I can try to solve them and can look at the solutions when I'm stucked.I'd like to get exercises about; Strings Arrays Pointers
1
2322
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 because the exercises tend to be overly trivial, but if someone knows of somewhere that I can get some general ideas for programming exercises then i'd appreciate it.
0
1416
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 learning. Has anyone done such a thing? Ben
0
3182
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 one? Thanks a million, my email address is meinanxiang@yahoo.com.cn
8
6668
by: jopy887 | last post by:
Hey people, Does someone know a good site for C exercises? For beginners.. Jonathan
176
8519
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 their own unit test framework, and then in a lab session see if I can get them to write their own. To give them an example I've created the following UTF class (with a simple test program following). I would welcome and suggestions on how anybody...
5
1905
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/ PermaLink,guid,f3b9ba36-848e-43f8-9caa-232ec216192d.aspx). The first exercise is this: "Write a program that takes as its first argument one of the words 'sum,' 'product,' 'mean,' or 'sqrt' and for further arguments a series of numbers. The program applies the...
2
2938
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 listening. I have been searching around for exercises to do, but I'm not finding any and what I do find does not correspond with what I've learned so far. I've even gone to samspublishing.com and they didn't have anything. I would greatly...
1
1663
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 that has to learn by doing. I've searched all over for either a book or website that would provide exercises to practice with and I haven't come up with anything. Does anyone know of a website or a book that covers this? Any help would be...
0
9748
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11020
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10670
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9506
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7907
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5736
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4549
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.