| kiste5 (5) | |
|
can someone expalain me this? i have no idea what i have to do.. • Write a program that asks the user to input an integer and then read the integer, • Modify the program so that your program reads three integers one at a time. Each time the program asks one integer to enter and then reads the integer. Use while loop to do this task. • Again modify your program which will also add all the integers and then display the final sum. | |
|
|
|
| L B (3805) | |
| What is the first confusing part to you? For me, I cannot understand why they would have you use a while loop instead of a for loop. | |
|
|
|
| Zereo (408) | |||
|
Probably because they usually teach while loops before for loops since they can be easier to understand when just beginning. Atleast I think? Anyways Like LB said not sure where you are stuck at here is a framework to get you started though.
| |||
|
Last edited on
|
|||
| kiste5 (5) | |
|
What do i put after while() to make it stop after 3 times? Thanks for the help btw, i really appreciate it | |
|
|
|
| L B (3805) | |
|
You need the loop condition. Recall how while loops work: http://www.cplusplus.com/doc/tutorial/control/#while You will need a variable to track the number of times the loop has run. | |
|
|
|
| kiste5 (5) | |
|
/Help please lol..i have no idea what im doing.. / Whileloop.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> using namespace std; int main() { int var1=1; int var2=2; int var3=3; while (var1,var2,var3>0) { cout << "Enter interger 1:" << endl; cin >> var1; cout << "Enter interger 2':" << endl; cin >> var2; cout << "Enter interger 3:" << endl; cin >> var3; cout << "Your numbers are:" << endl; cout << var1; cout <<","; cout << var2; cout <<","; cout << var3; // For step 3 you will need to add all three integers together (hint use // another variable to hold them) } system("Pause"); // For step 3 display the final sum return 0; } | |
|
Last edited on
|
|
| supperpiccle (67) | |||
you have it where it goes through all three....three different times....for loop would make more sense but here is how the loop should look
| |||
|
Last edited on
|
|||
| supperpiccle (67) | |
| Can you use an array? | |
|
|
|
| Zereo (408) | |
| There is no need for a array it would just complicate things. Also there is no need for 3 different variables. All the homework assignment says to do is have the user input 3 numbers and print each number as it is entered. So you can use one variable for that. For the third atep you need to create a new variable and just add each number the user enteres to it. | |
|
|
|
| kiste5 (5) | |||
Ok this is the latest i did..the program complies but it has some weird results coming up
| |||
|
|
|||