A program that doesn't work

teschan -  
[Dal] Posted messages 6122 Registration date   Status Contributor Last intervention   -

hello.

I would like to submit my program because it does not work although I do not see the error, could you help me please thank you.

Here is the code :

#include <iostream> #include <cmath> using namespace std; int main () { int a; int b; int resultat; cout<<"enter a number"<<endl; cin>>a; cout<<"enter a second number"<<endl; cin>>b;  resultat = pow(a,b); cout << "The power of " << number << " is " << resultat <<endl; reuturn 0; }

***** For easier reading of the code, in the future use the code tags.

4 answers

diablo13800 Posted messages 3469 Registration date   Status Member Last intervention   1 872
 

Hello,

The error is in the last line which contains a typo. reuturn does not exist.


To conquer without peril is to triumph without glory.
Pierre Corneille, Le Cid

0
[Dal] Posted messages 6122 Registration date   Status Contributor Last intervention   1 108
 

Hello, teschan

"number" is not a declared variable either.

These errors are described by the compiler.

Isn't it more efficient to look at the error messages than to post a question "it doesn't work" on a forum?

0
noriega6666 Posted messages 17 Status Member
 

Here, I declared resultat but it's still not working: here is my source code:

#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int a;
    int b;
   int resultat;
    cout<<"enter a number"<<endl;
    cin>>a;
    cout<<"enter a second number"<<endl;
cin>>b;
 resultat = pow(a,b);
return 0;
}
Please respond to me as soon as possible.

0
[Dal] Posted messages 6122 Registration date   Status Contributor Last intervention   1 108
 

Here is what the compiler says when asked to display warnings:

 $ g++ -Wall -Wextra 37958782.cpp 37958782.cpp: In function ‘int main()’: 37958782.cpp:10:8: warning: variable ‘resultat’ set but not used [-Wunused-but-set-variable] int resultat; ^~~~~~~~ 

It tells you that you have assigned something to the variable "resultat" but that you are not using this variable.

If you expect your program to display the result... why are you not displaying it?

0
diablo13800 Posted messages 3469 Registration date   Status Member Last intervention   1 872
 

Hello,

Simply saying "It doesn't work" doesn't help at all. Please specify if you have an error, if the program launches without doing anything, or if you simply didn't get the expected result.


To conquer without peril is to triumph without glory.
Pierre Corneille, Le Cid

0