0

hi,please help me with this program ,iwant it to print values of x not x

#include <iostream>
using namespace std;
int main()
{
int x = 5;
while(x < 7)
{
    std::cout<<" value of x"<<'\n';
x=x+1;
}
    while(x > 7)
    {
        std::cout<<" value of x"<<'\n';
        x=x-2;
        }
return 0;
}

Edited by Nick Evan: Fixed formatting

4
Contributors
11
Replies
12
Views
5 Years
Discussion Span
Last Post by Ezzaral
0

So tell it to. You're only going to get output if you tell it to generate output and what to output.

int someValue = 10;
cout << "The value of someValue is: " << someValue << endl;

Edited by Fbody: n/a

0

may be you don't understand me,i want the program to show the values of x on the screan dump

0

I understand perfectly. It's not going to output the value of a variable unless you include that variable in the output statement:

#include <iostream>
using std::cout;
using std::endl;
using std::cin;

int main() {
  int someValue = 10;
  cout << "The value of someValue is: " << someValue << endl; //pay close attention to this line
  cin.get();
  return 0;
}

Edited by Fbody: n/a

0

#include <iostream>
using std::endl;
using std::cin;
int main()
{
int x = 5;
while(x < 7)
{
std::cout<<" value of x."<<x<<'\n';
x=x+1;
}
while(x > 7)
{
std::cout<<" value of x."<<x<<'\n';
x=x-2;
cin.get();
}
return 0;
}

0

i think may there is problem with braces because error type is one or more multiple files used

0

What you've posted compiles and runs properly. If you can't compile, you'll have to check your compilation settings.

0

It is okay thanks,but what iwas looking for is for the program to produce output like this:567753

#include <iostream>
using std::endl;
using std::cin;
int main()
{
int x = 5;
while(x < 7)
{
std::cout<<" value of x."<<x<<'\n';
x=x+1;
}
while(x > 2)
{
std::cout<<" value of x."<<x<<'\n';
x=x-2;
cin.get();
}
return 0;
}

0

Then take out all the "fluff" you've put in your output statements. You're going to get as much or as little as you put into the statement, add or remove as necessary to get what you want.

And please start using [code] ...code tags... [/code]. I haven't said anything, but you have enough posts you should know by now.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.