นะวู
Ilya
Tazin
#include<iostream>
#include<string>
using namespace std;
void input(string a, string b){
cout<<"Enter your username "<<endl;
cin>>a;
cout<<"Enter your password "<<endl;
cin>>b;
}
int main(){
string uname, pass;
input(uname, pass);
//int i=0;
for(int i=0; i<=3; i++)
{
if (uname=="Yakushi" && pass=="ABCK")
{
cout<<"login successful ";
break;
}
else
cout<<"Wrong username or password. Try again."<<endl;
input(uname,pass);
}
cout<<"Bye bye";
return 0;
}
Tazin
Can anyone see what's wrong here ?
\Device\NUL
Tazin
whatever I input it shows wrong username
Tazin
\Device\NUL
It doesn't refer to uname and pass variable outside the function
Tazin
Ohh
Tazin
So should I just remove function and take input manually?
Tazin
Or there is another way to use function here
\Device\NUL
\Device\NUL
\Device\NUL
void input(string& a, string& b);
\Device\NUL
Deepak Chaurasia
\Device\NUL
Similar to what std::cin do, it use type-reference
\Device\NUL
Which is why std::cin does not require the reference of the input but scanf require it
Deepak Chaurasia
Here you guys are talking about call be refrence or any other topic?
\Device\NUL
With pointers
void func(int *a, int *b)
func(&ref, &ano_ref)
With reference
void func(int &a, int &b)
func(ref, ano_ref)
\Device\NUL
Afaik, it's only aliases
Deepak Chaurasia
What is ref and ano_ref
Deepak Chaurasia
Sorry , but i am beginner
mito
Deepak Chaurasia
mito
I use the pass by pointers all the time.
Tazin
\Device\NUL
\Device\NUL
but reference is commonly used with object
\Device\NUL
https://isocpp.org/wiki/faq/references
\Device\NUL
https://isocpp.org/wiki/faq/references#refs-vs-ptrs
Ramil
any good resources on how to code C style C++? Also like to know what are the costs of doing so in a real-life production work
Anatolii
Hi guys! I have a program in C which checks number for repeated digits. It's done by using boolean array and the reason why I'm asking is that I can't completely understand it. To be exact, I'm not sure how does the if statement work on the line 16. I have my code on Hastebin as it's said in the rules. Here's the link https://hastebin.com/tojayeyaca.cpp Thank you in advance!
Asker
Hi everyone I am begginer Please help me for finding problem there
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int n;
cin>>n;
if (10<=n<=99)
cout<<pow((n/10+(n-n/10*10),2));
}
Anonymous
Asker
Thanks
klimi
the problem is the pow call which doesn't take int as first argument
klimi
ah nah, you just messed up the )
klimi
pow takes 2 parameters, you have only 1
Anonymous
Anonymous
klimi
klimi
klimi
he has first (n/10+(n-n/10*10),2) and there is no second
Anonymous
,2 is the second one
klimi
no
klimi
that would have to be
cout<<pow((n/10+(n-n/10*10),2),2);
Anonymous
What's the syntax for pow
klimi
alright, i'll look into the specification
klimi
nope... it seems it takes only float/double as first argument and int/float/double as the second
Anonymous
klimi
Is their any specific error
it doesn't compile due to
test.cpp: In function ‘int main()’:
test.cpp:9:10: error: no matching function for call to ‘pow(double)’
9 | cout<<pow(static_cast<double>(n/10+(n-n/10*10),2));
because it has only one parameter
Asker
Thanks
Anonymous
Anonymous
Thanks dude
Asker
Olivia
#include<iostream>
#include<vector>
using namespace std;
int main(){
vector<int> v1;
for(int i=1; i<5; i++)
v1.push_back(i);
cout<<v1.size()<<endl;
cout<<v1.capacity()<<endl;
v1.resize(7);
cout<<v1.size();
v1.shrink_to_fit();
for(auto it=v1.begin(); it!=v1.end(); i++)
cout<<*it;
return 0;
}
Olivia
Why it shows error in data type
Konstantin
Olivia
Olivia
Olivia
Sorry but i cant understand
Konstantin
#include <iostream>
#include <vector>
using namespace std;
int main(){
vector<int> v1;
for(int i=1; i<5; i++)
v1.push_back(i);
cout<<v1.size()<<endl;
cout<<v1.capacity()<<endl;
v1.resize(7);
cout<<v1.size();
v1.shrink_to_fit();
for(auto it=v1.begin(); it!=v1.end(); it++)
cout<<*it;
return 0;
}
Olivia
Konstantin
it works with no datatype errors
Olivia
Nah still not worrking