Solving problem with nested loops.

Hello I have to make program that solves equation like this:

x=y*E*6.6(0.7-z) where 'z' is going from -1 to 5 with step size 0.2 .When 'z' is between 0.6 and 1 'y' changes to 0.82 and for the other cases 'y' = 0.63.
Prin x,y,z.

The code I wrote is:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream.h>
#include <stdio.h>
#include <math.h>

 float const E=0.1;


 int main ()

{
 float x,y,z;
 z=-1;

 do
  {
   x=y*E*6.6(0.7-z);
   z=z+0.2;
    if(z=>0.6 || z<=1)
    {
     y=0.63;
     }
      else
       { y=0.68;
        }
   }while(z<=5)



getchar ();
return 0;
}


So far,but I get too many errors.I'll be pleased if someone help me I'm kinda lost.
Errors I get:
(18,12) : Call of nonfunction.
(25,5) : If statement missing )
(31,1) : do statements must have while
(32,1) : Compound statement missing }
(32,1) : 'x' is declared but never used
(32,1) : 'y' is declared but never used
Last edited on
Hey and welcome, could you please edit your post and use code tags - http://www.cplusplus.com/articles/jEywvCM9/

Also, if you got errors. Please copy paste them.
Hi and thanks.I edited my post :))
Hi,

You are missing an operator on line 16, did you mean:

x=y*E*6.6 * (0.7-z);

Also missing semi-colon line 25.

this:

z=z+0.2;

is better written:

z += 0.2;

A consistent indenting / bracing style would also be good :+)

Good Luck :+)

Edit:

Line 18 : operator <= not =>
Last edited on
Thank you very much!Now its working fine.Theres only one thing.When i start it it gives me for x= ; y= ; z= ; only one value I need it to print the values for each step.

Redacted version:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream.h>
#include <stdio.h>
#include <math.h>

 float const E=0.1;


 int main ()

{

 float x,y,z;
 z=-1;

 do{
    x=y*E*6.6*(0.7-z);
    z += 0.2;
    if(z<=0.6 || z<=1){
     y=0.63;
    }
    else
    {
     y=0.68;

    }
    }
   while(z<=5);

  cout<<"x= "<<cout<<x;
  cout<<"y= "<<cout<<y;
  cout<<"z= "<<cout<<z;


getchar ();
return 0;
}
Last edited on
Hi,

Also, it is <iostream> and <cmath>, you have the C style inclusions.

When i start it it gives me for x= ; y= ; z= ; only one value I need it to print the values for each step.


Well your program doesn't print anything, and it is not clear whether you want to do a C program or C++. Presumably C++, seen as you include iostream.

If so, place std::cout statements before the end of the do loop.

Im making a C++ program sorry for my bad coding if I even can call t like that I'm in yet in the begining to get the idea here.When I place std::cout it gives me another error saying.

Warn : NONAME00.CPP(16,7):Possible use of 'y' before definition
Error: NONAME00.CPP(29,19):Qualifier 'std' is not a class or namespace name
Error: NONAME00.CPP(29,21):Statement missing ;
Warn : NONAME00.CPP(36,2):'x' is assigned a value that is never used
You should show us your updated program, you get new errors with a new program that we do not know of.


Statement missing ; That's an obvious error, but you'd have to post your program so we can find it.

Qualifier 'std' is not a class or namespace name Did you do what TheIdeasMan told you? It's suppose to be

<iostream> and <cmath>
Last edited on
Here it is.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include <stdio.h>
#include <cmath>

 float const E=0.1;


 int main ()

{

 float x,y,z;
 z=-1;

 do{
    x=y*E*6.6*(0.7-z);
    z += 0.2;
    if(z<=0.6 || z<=1){
     y=0.63;
    }
    else
    {
     y=0.68;
    }
    std::cout<<x;
    std::cout<<y;
    std::cout<<z;
    }
   while(z<=5);




getchar ();
return 0;
}



Error: NONAME00.CPP(3,2):Unable to open include file 'CMATH.h'
Warn : NONAME00.CPP(16,7):Possible use of 'y' before definition
Error: NONAME00.CPP(25,8):Qualifier 'std' is not a class or namespace name
Error: NONAME00.CPP(25,10):Statement missing ;
Error: NONAME00.CPP(26,8):Qualifier 'std' is not a class or namespace name
Error: NONAME00.CPP(26,10):Statement missing ;
Error: NONAME00.CPP(27,8):Qualifier 'std' is not a class or namespace name
Error: NONAME00.CPP(27,10):Statement missing ;
Warn : NONAME00.CPP(36,2):'x' is assigned a value that is never used
x=y*E*6.6*(0.7-z); You're using y, but what is y? you use it before it has a value.

You sure those are the errors you get from this program? It works fine for me once I initialize y to something.

Error: NONAME00.CPP(3,2):Unable to open include file 'CMATH.h' You can't be getting this error when you dont even use cmath.h.
Last edited on
Thats a parameter that changes.When z is between 0.6 and 1 y is assigned as y=0.86 for the rest values for z (from -1 to 5) y=0.63.

Positive.Im writing it on Borland C++ 5.02 maybe thats the problem and those are the error it shows after I compile it.

Just to try it out I pasted the formula above after the "while" with the original
1
2
3
#include <iostream.h>
#include <stdio.h>
#include <math.h> 

I dont have errors from it now,but when I run it it still doesnt print me all the values :/
Last edited on
Yeah, Borland C++ 5.02 uses a very old version of the standard.
can u help me with this pliz?
Write a C++ code that implements a Doubly Linked List structure that contains Integer
elements, and then do the following:
1. Implement the necessary member functions (insert, display, and search).
2. Implement a function “DoublyLinkedList getUnion(DoublyLinkedList L2)” that
displays the union of the calling list (L1) and L2.
3. Implement a sample run of the getUnion function.
Example: input L1 = 1, 2, 3, 4
L2 = 2, 5, 4, 6
output L3 = 1, 2, 3, 4, 5, 6
@beyruz

Start your own topic, don't gate crash someone else's.
@Ashckroft

I would recommend getting a better compiler, clang with gcc is really good.

TarikNeaj is right y has to be initialised. Always initialise your variables to something.
Topic archived. No new replies allowed.