Beginner C/C++

Moderators: None (Apply to moderate this forum)
Number of threads: 5428
Number of posts: 16943

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
do while loop Posted by bueno77 on 1 Apr 2011 at 7:43 AM
ya i could use some help. everything is compiled but it doesnt run like its suppose to. I get a long list of 1.#INF. it doesnt even let me exit like its suppose to.

//Lab 10 Problem 1
#include<iostream>
#include<cmath>
using namespace std;

int main()
{
//variables defined here
float x, y, stop, start;
char exit_variable;

//data input section
cout << "Enter in the value for x " << x << "\n";
cout << "Enter in the value for y " << y << "\n";
cout << "Enter in the value that you want x to start at " << start << "\n";
cout << "Enter in the value that you want x to stop at " << stop << "\n";

//math stuff
y = (pow(x,3) - 2 * x + 10);

//Do loop
x = start;
do
{
cout << " The answer to the equation is " << y << "\n";
x=x+1;
}

//While loop
while (x = stop);
cout << "The x value has reached the stopping point \n" ;

//data output section
cout << "Press the letter e to exit ";
cin >> exit_variable;
//thats the end
}
Report
Re: do while loop Posted by Newb1001 on 1 Apr 2011 at 8:35 AM
Hello bueno77,

if you are writing in c++ try writing your script like this,

int main ()

int , ;
char ;

do {
cout<<
cin>>

//and main function//
}
while ( a != b)
}

Newb1001
p.s. I'm no expert. It took me 3 do-while loops, one if-else and 2 switch-case scripts to program a calculator capable of doing exponents and basic arithmatic. Some compilers wont recognise 'exit (0)' or 'exit (1)' depending but ' return 0;' will work.
Report
Re: do while loop Posted by pseudocoder on 1 Apr 2011 at 7:01 PM
if the code you've submitted is what you're using, then you're using uninitialized data in x, y, start, and stop.

while(x = stop); this isn't what you'd want; your comparison will be something like != (not equal to), == (equal to), >= (greater / equal to), or <= (less than equal to).

y looks like it should be computed within the do-while if you're incrementing x.

what is your program supposed to do?





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.