Hi to all
I have a small piece of code. Looks fine, but nothig shows up on the screen, it should though. Could anybody tell me why is that? Is there aany possibility that samething wrong with Dev c++. If so,How may I fix it
Thank you
This is piece of code
include<iostream>
include<cstring>
void swap(char& temporary1,char& temporary2);
int main()
{
using namespace std;
string word,temp;
int end;
cout<<"What is the word you would like to reverse: ";
cin>>word;
By the way, please be careful with your thread titles.
This was not a "Dev c++ problem", it was the result of code that was flawed.
There's nothing criminal about that, my hacked up code is also flawed, but
done in such a way as to show you something. But when you say what your thread
title is, the message coming across is that you are blaming the tool.
This is a bad idea from a question asking standpoint, and bad logic as well.
I have been programming for over 30 years now, and I can count on one hand the
number of times that the tool was at fault for something - the rest of the
time it was just plain Jane Wayne stupidity....
Wayne
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Look into how you are using the variable "temp". It appears to be set locally to the function "swap", yet you turn around and use it in "main" like it was the same variable.
It's not, just because it is declared in two places.
Consider this hacked up code - not fit for turning in as homework by the way:
include<iostream>
include<cstring>
using namespace std;
void swap(char& temporary1,char& temporary2);
int main()
{
string word,temp;
int end;
cout<<"What is the word you would like to reverse: ";
cin>>word;
end=word.length() - 1;
int start=0;
while (start<end)
{
swap(word[start],word[end]);
start++;
end--;
Hi to all
I have a small piece of code. Looks fine, but nothig shows up on the screen, it should though. Could anybody tell me why is that? Is there aany possibility that samething wrong with Dev c++. If so,How may I fix it
Thank you
This is piece of code
include<iostream>
include<cstring>
void swap(char& temporary1,char& temporary2);
int main()
{
using namespace std;
string word,temp;
int end;
cout<<"What is the word you would like to reverse: ";
cin>>word;
}
void swap(char& temporary1,char& temporary2)
{
using namespace std;
char temp=temporary2;
temporary2=temporary1;
temporary1=temp;
}
By the way, please be careful with your thread titles.
This was not a "Dev c++ problem", it was the result of code that was flawed.
There's nothing criminal about that, my hacked up code is also flawed, but
done in such a way as to show you something. But when you say what your thread
title is, the message coming across is that you are blaming the tool.
This is a bad idea from a question asking standpoint, and bad logic as well.
I have been programming for over 30 years now, and I can count on one hand the
number of times that the tool was at fault for something - the rest of the
time it was just plain Jane Wayne stupidity....
Wayne
People blaming the compiler for their own stupid shortsighted errors? I don't believe it.
Look into how you are using the variable "temp". It appears to be set locally to the function "swap", yet you turn around and use it in "main" like it was the same variable.
It's not, just because it is declared in two places.
Consider this hacked up code - not fit for turning in as homework by the way:
include<iostream>
include<cstring>
using namespace std;
void swap(char& temporary1,char& temporary2);
int main()
{
string word,temp;
int end;
cout<<"What is the word you would like to reverse: ";
cin>>word;
end=word.length() - 1;
int start=0;
while (start<end)
{
swap(word[start],word[end]);
start++;
end--;
}
cout<<word<<endl;
system("pause");
return 0;
}
void swap(char& temporary1,char& temporary2)
{
char temp=temporary2;
temporary2=temporary1;
temporary1=temp;
}
How does this code work differently than yours, and why?