Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I tried as I/P: 100, 10, 1 and it works fine so CI = 10 and total = 110
But with other example I can't get right answer can you please tell me what to do.
I tried to look at other questions here but I can't understand what the wrong I did.
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
float amount,rate,time_,total,compoundedInterest;
cout<<"Amount: ";cin>>amount;
cout<<"Rate of Interest: ";cin>>rate;
cout<<"Time: ";cin>>time_;
compoundedInterest=amount*pow((rate/100),time_);
total=amount+compoundedInterest;
cout<<"Compounded Interest: "<<compoundedInterest;
cout << endl;
cout<<"Total: "<<total;
return 0;
}
Please Help me figure what is the problem.
Code:
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
float amount,rate,time_,total,compoundedInterest;
cout<<"Amount: ";cin>>amount;
cout<<"Rate of Interest: ";cin>>rate;
cout<<"Time: ";cin>>time_;
compoundedInterest=amount*pow((1+rate/100),time_)-amount;
total=amount+compoundedInterest;
cout<<"Compounded Interest: "<<compoundedInterest;
cout << endl;
cout<<"Total: "<<total;
return 0;
}
Problem:
The main problem with your CI rule it is wrong that is why you will find wrong O/P.
You can use this code which will works fine with you.
Rules:
Note:
I used the first rule to calculate CI here.
Resource:
Link1
Link2
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last month.
This post was edited and submitted for review last month and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I have following program and i want the output to be 10.0
what line of code I have to add in function fun so that i have desired output.
#include<bits/stdc++.h>
using namespace std;
float fun(float a)
{
return a;
}
int main()
{
float a = 10;
cout << fun(a);
return 0;
}
I tried using setprecision() but it is often used with cout. How it can be used when returning the output? I am stuck here.
Nothing to stop this
float fun(float a)
{
cout << fixed << setprecision(1);
return a;
}
But that's stupid code for a stupid puzzle. What does this have to do with real programming?
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Why is the result I output on the oj website all 0? Ans defines global variables, and all the values output on Oj are global variables, and the global variables have not changed. But the test samples are output on the local compiler The example can output the correct result.
code:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
int n,k,ans=0;
char g[100][100];
bool flagx[100],flagy[100];
//int dirx[4]={-1,0,1,0};//上右下左;
//int diry[4]={0,1,0,-1};
void dfs(int x,int y,int use)
{
if(use==k)
{
ans++;
return ;
}
if(y==n) y=0,x++;
if(x==n)
return;
//不放
dfs(x,y+1,use);
//放
if(x>=0&&x<n&&y>=0&&y<n&&g[x][y]=='#'&&!flagx[x]&&!flagy[y])
{
flagx[x]=true;
flagy[y]=true;//标记该位置已经放过棋子;
dfs(x,y+1,use+1);
flagx[x]=false;
flagy[y]=false;
}
//}
}
int main()
{
while(scanf("%d %d",&n,&k))
{
memset(flagx,'false',sizeof(flagx));
memset(flagy,'false',sizeof(flagy));
//memset(g,'')
if(n==-1&&k==-1)
break;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
cin>>g[i][j];
dfs(0,0,0);//x,y,ans;坐标,放置的棋子的个数;
cout<<ans<<endl;
ans=0;
}
return 0;
}
You can consider this screenshot:
Unfortunately, the site of your school (which you could include in the question) does not load on my system.
I think that the expected result should depend on the input for n and k at least. What is the result if you input n=1, k=0? I would expect aws=1 from reading your code.
Notice that in your case, the dfs method is exclusively called in the line dfs(0,0,0). I don't know, if that is intended, as the comments are in chinese.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
#include<bits/stdc++.h>
using namespace std;
int main()
{
int x,y;
while(cin)
cin>>x>>y;
cout<<"YES";
}
here for which input it will print out "YES"?
is cout is logic 1 or 0?
This will print "YES" for any input (except for an infinite stream of valid input, in which case it'll run forever and never print anything).
You forgot braces for your loop, so the cout statement is not actually in the loop.
Your cout is in no way conditional on the values you read in.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
ideone link: https://ideone.com/hOBBMA
problem link: http://www.spoj.com/problems/OFFSIDE/
code:
enter code here
#include <iostream>
using namespace std;
int main() {
int n1,n2,i,j;
while(1)
{
int count=0;
cin>>n1>>n2;
if(n1==0 && n2==0)
break;
else
{
int a[n1],d[n2];
for(i=0;i<n1;i++)
{
cin>>a[i];
}
for(i=0;i<n2;i++)
{
cin>>d[i];
}
for(i=0;i<n1;i++)
{
for(j=0;j<n2;j++)
{
if(a[i]>d[j])
{
count++;
}
}
}
}
if(count>=2)
cout<<"N"<<endl;
else
cout<<"Y"<<endl;
}
return 0;
}
it gives the correct answer with the given test cases but apparently it's a WA
Consider this input; two attackers at 400m from the goal and two defenders also at 400m from the goal. Your code would count '0' i.e. offside whilst according to the rules neither of the attackers isn't.
An attacking player is offside if he is nearer to his opponents’ goal
line than the second last opponent. [This is not true for any of the attackers in this case so definitely not an offside]
A player is not offside if he is level with the second last opponent [In this case they are level so certainly not offside] or he is level with the last two opponents [And this is true too].
2 2
400 400
400 400
0 0
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am very confused. Why does this work:
double doubleValue = 20;
NcVar variable = {some process obtaining an instance}
map<NcVar,double> th;
th.insert(std::make_pair(variable, doubleValue));
and this fails:
double doubleValue = 20;
NcVar variable = {some process obtaining an instance}
map<NcVar,double> *th = new map<NcVar,double>();
th->insert(std::make_pair(variable, doubleValue));
That means, the first variant ends up with one key/value-pair, while the second leaves the map unchanged (0 entries)?
Works for me:
#include <map>
#include <iostream>
using namespace std;
int main(){
typedef map<int,float> mapp;
mapp map1;
map1.insert(make_pair(1,1.1));
mapp * mp2 = new mapp();
mp2->insert(make_pair(2,2.2));
cout << map1.begin()->second << endl;
cout << mp2->begin()->second <<endl;
return 0;
}
And output:
$g++ map_test.cpp
$ ./a.out
1.1
2.2
Thanks for the help, guys. I feel kinda stupid now. The assumption that the map was empty was based on the appearance in the debugger. I am using XCode as IDE and when using a pointer to map, it would simply mess up and display the map as empty. Using cout revealed the truth.