Need help with a assignment

There's a flow chart for an algorithm that displays the numbers 20,40,60,80,100,120,140,160 and 180 on the screen. Code the algorithm into a program; use the while statement the counter variable should be an int variable named number then enter your c++ instructions into a source file named inroductory23.cpp

Add 10 to counter

^
|
Flow chart is this Display counter multiplied by 2
^

|
Start--->Initialize counter to 10---->Counter < 100 -----> stop


Personally I don't know where to start... was just looking for alot of help =(
up
closed account (o1vk4iN6)
Use a for loop. If this is an assignment look over the notes for last week and you shall find the pieces to the puzzle (assignment) to solve it.
Yeah my teacher doesn't give notes, he gives us the book. and to be honest lets face it... the book just sucks when you're trying to compare it to visual studio 2010 c++


I really need to be shown how to do this... god forbid you do it for me, whoever does.

If I know how to do it, i'll be able to use it for notes for other assignments.



Edit: and sorry if I seem angry... I am just really frustrated with this whole thing, I asked my teacher for help and I did not receive it, I was just shown examples from the book that did not even attain to the assignment itself
Last edited on
closed account (o1vk4iN6)
Does the examples come with explanations ? If anything you can compile the examples and see what they do. If you don't understand specifically what something does we can explain it. You have written a program yes ? Just take pieces of what you already know and put them together to make it do what you want.

You want to use some sort of loop, there are a couple. For loop, while loop, do while, etc... Loop for those, learn the syntax as well as how to use it.

You also want to display something on the console, you can use an output stream (std::cout, std::cerr, std::clog, etc...) which is the standard C++ way. You can also use printf() from the C stdlib.h, but that is mostly for compatibility with C.

It's really hard to use a book unless you read it through and through as you don't know what tools are available to you. I know it's a bitch but trying to jump in the middle is probably the hardest and most frustrating way to learn something.
Last edited on
int main()
{
int a = 20;
int b = 40;
int c = 60;
int d = 80;
int e = 100;
int f = 120;
int g = 140;
int h = 160;
int i = 180;


int counter = 10;

while (counter < 100){
cout << "counter is " << counter << endl;
counter = counter * 2;
counter = counter + 10;
}




This is what I have done basically... I need to display those numbers up there... and the while statement is that I think
closed account (o1vk4iN6)
And what is the output ? Is it the desired output you want ?
That is a problem.... I don't know the assignment I posted at the start of this thread is all it gave me, so what should my output be? =-\
Basically yes I want the output... but what do those list of numbers have anything to do with the counter?
closed account (o1vk4iN6)
The counter and while statement meet the assignment criteria but I don't think the output is correct.

pbplayer9 wrote:
algorithm that displays the numbers 20,40,60,80,100,120,140,160 and 180 on the screen


So what numbers does your code display ? Compile the code and see if you get the desired numbers.
alright, I am indeed having a different problem on top of this with visual studio... I cannot compile anything due to a fatal header error... Here's what it says... and I will also link the FULL code that I am using


>c:\users\daylen\documents\visual studio 2010\projects\introductory23.cpp\introductory23.cpp\introductory23.cpp.cpp(35): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?


// Introductory23.cpp.cpp : Defines the entry point for the console application.
//
#include <iostream>
using namespace std;


int main()

int main()
{
int a = 20;
int b = 40;
int c = 60;
int d = 80;
int e = 100;
int f = 120;
int g = 140;
int h = 160;
int i = 180;


int number = 10;

while (number < 100){
cout << "number is " << number << endl;
number = number * 2;
number = number + 10;
}




Now when I try to actually use the
closed account (o1vk4iN6)
It's a compiler setting, use google to search how to disable it or just add that header file.
Topic archived. No new replies allowed.