if语句加分号意味着语句结束,必须紧接着else才有效,否则else找不到if。
能编个毛线衣吗?
#include<math.h> #include<stdio.h> #include<iostream> using namespace std; void main() { double s,h,p1,p,p0,a,v,w,p2; w=215*3.14/30,h=30,p0=90,p1=90,p=0,p2=190,p=0; for(;p<=190;p=p+5) { //0-45 ->p if(0<=p&&p<=45) {s=2*h*p*p/p0*p0; v=4*h*w*p/p0*p0; a=4*h*w*w/p0*p0; cout<<a<<" "<<v<<" "<<s<<endl; } else { if(45<p&&p<=90) { s=(h-2*h*(p0-p)*(p0-p))/p0*p0; v=4*h*w*(p0-p)/p0*p0; a=-4*h*w*w/p0*p0; cout<<a<<" "<<v<<" "<<s<<endl;} else if(100<=p&&p<=145) {s=(h-2*h*(p-100))/p0*p0; v=-4*h*w*(p-100)/p0*p0; a=-4*h*w*w/p0*p0; cout<<a<<" "<<v<<" "<<s<<endl; } else { s=2*h*(p2-p)*(p2-p)/p0*p0; v=-4*h*w*(p2-p)/p0*p0; a=4*h*w*w/p0*p0; cout<<a<<" "<<v<<" "<<s<<endl; } } } }