有5个学生和3个科目。我的问题是,当计算每个学生的平均分数时,前一个学生的平均分数被加到刚刚计算的平均分数之后! 任何人都可以弄清楚这段代码中的错误或遗漏了什么!谢谢:))
- (instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { {
return [super initWithNibName:@"YourXibName" bundle:nil]);
}
答案 0 :(得分:3)
您需要为for循环中的每个学生分配total
到0
。类似的东西:
for(j=1;j<=5;j++)
{
cout<<"Marks for Student"<<j<<":"<<endl;
total = 0.0;
for(i=1;i<=3;i++)
{
cout<<" subject"<<i<<":";
cin>>scores;
total+=scores;
}
ave=total/3;
cout<<endl;
}
答案 1 :(得分:1)
你没有&#34;归零&#34;在进行下一次平均计算时,你的总计数器。如果逐行逐步执行代码,这将是一个微不足道的问题。
如果你现在不练习,那么解决更复杂的问题就难以置信。您提出的下一个问题,请发布您尝试过的内容。
[1/25/16 10:55:46:950 CST] 0000001c SystemOut 0 CalSMTJPA INFO
[WebContainer : 0] openjpa.Runtime - Starting OpenJPA 1.2.1-SNAPSHOT+OPENJPA-679-Final
[1/25/16 10:55:46:950 CST] 0000001c SystemOut O 15 CalSMTJPA INFO [WebContainer : 0]
openjpa.jdbc.JDBC - Using dictionary class "com.ibm.ws.persistence.jdbc.sql.SQLServerDictionary" (Microsoft SQL Server 11.00.5058 ,Microsoft SQL Server JDBC Driver 2.0 2.0.1803.100).
[1/25/16 10:55:46:950 CST] 0000001c servlet E com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0068E:
Uncaught exception created in one of the service methods of the servlet /Home.jsp in application CalSMTEAR.
Exception created : <openjpa-1.2.1-SNAPSHOT+OPENJPA-679-Final-r422266:746282 nonfatal general error>
****org.apache.openjpa.persistence.PersistenceException: For input string: "JDBC"****
at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:196)
at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:142)
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:192)
at com.ibm.ws.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:42)
at com.ibm.ws.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:27)
at entities.controller.PlatformsManager.getEntityManager(PlatformsManager.java:43)
at entities.controller.PlatformsManager.getPlatforms(PlatformsManager.java:136)
at com.ibm._jsp._Home._jspService(_Home.java:90)
at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1461)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:793)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:444)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:175)
at com.ibm.wsspi.webcontainer.servlet.GenericServletWrapper.handleRequest(GenericServletWrapper.java:121)
at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.handleRequest(AbstractJSPExtensionServletWrapper.java:234)
at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionProcessor.handleRequest(AbstractJSPExtensionProcessor.java:337)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3622)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:276)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:927)
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1566)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:175)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:455)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:384)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:272)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1527)