c - 铅电池实验室 - 普克特定律

标签 c

基本上,它要求“输入两组...”的部分循环两次,我只希望在做出这两个决定后运行一次。请注意,我还没有编写用于决定输入一个带有保留的评级的代码。这是 C 语言编程。

#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<conio.h>

int main()
{
    double current1;
    double current2;
    double capacity1;
    double capacity2;
    double time1;
    double time2;
    double exponent1;
    double exponent2;
    double counter;
    double ampereh1;
    double ampereh2;
    double decision;
    double c1,c2,r1,r2;
    double reserve;
    double limit;
    double decision2;
    double decision3;

    printf("Lead Acid Battery - Peukert's Law\n\nThis program allows for the user to input battery specs and calculate\nvalues from peukert's variables.\n");

    printf("\nSelect an increment value: "); /*User will input how much the initial value will increase by for each row in the column calculated*/
    scanf("%lf", &counter);
    printf("What format would you like?\n(Format 1: Press 1, Format 2: Press 2): ");  /*Format 1 describes input of current, Format 2 describes input of time*/
    scanf("%lf", &decision);

    if (decision == 1)
    {
        printf("Two ratings or one rating w/ reserve (Press 1/2): ");
        scanf("%lf", &decision2);
    }

    if (decision2 == 1);
    {
        printf("Input two sets of hourly rate capacity (hours) then ah capacity (ampere hours):\n");  /*User will input each set of r capacity and ah capacity*/
        scanf("%lf %lf %lf %lf", &r1, &c1, &r2, &c2);
        printf("Input reserve capacity (mins): ");
        scanf("%lf", &reserve);
        exponent1 = (log(r2/r1))/(log(c1/r1)-log(c2/r2));
        capacity1 = r1 * pow((c1/r1),exponent1);
        printf("Select initial Electrical Current value: ");  /*User can choose any initial value to start from in row one within the table*/
        scanf("%lf", &current1);
        printf("Maximum value of electrical current to calculate until: ");
        scanf("%lf", &limit); /*User can choose the maxiumum value on the table of the initial value to increase to*/
        printf("Electrical\tDischarge\tAh\n");
        printf("Current\t\tTime\t\tCapacity\n");


        for (current1;current1<=limit;current1+=counter)
        { /*Will loop until table is finished up to the limit's maxiumum value that the user inputed*/

            time1 = capacity1/pow(current1,exponent1);
            ampereh1 = current1*time1;
            printf("%lf\t%lf\t%lf\n", current1, time1, ampereh1);

        }
        printf("Peukert's Exponent: %lf\n", exponent1);
        printf("Reserve Capacity (minutes): %lf\n", reserve);
    }

    if (decision == 2)
    {
        printf("Two ratings or one rating w/ reserve (Press 1/2): ");
        scanf("%lf", &decision3);
    }

    if (decision3 == 1);
    {
        printf("Input two sets of hourly rate (hours) and then capacity (ampere hours):\n");
        scanf("%lf %lf %lf %lf", &r1, &c1, &r2, &c2);
        printf("Input reserve capacity (mins): ");
        scanf("%lf", &reserve);
        exponent2 = (log(r2/r1))/(log(c1/r1)-log(c2/r2));
        capacity2 = r1 * pow((c1/r1),exponent2);
        printf("Select initial Time value: ");
        scanf("%lf", &time2);
        printf("Maximum value of time to calculate until: ");
        scanf("%lf", &limit);
        printf("Discharge\tElectric\tAh\n");
        printf("Time\t\tCurrent\t\tCapacity\n");

        for(time2;time2<=limit;time2+=counter){
            current2 = pow(capacity2/time2,1/exponent2);
            ampereh2 = current2*time2;
            printf("%lf\t%lf\t%lf\n", time2, current2, ampereh2);
        }

        printf("Peukert's Exponent: %lf\n", exponent2);
        printf("Reserve Capacity (minutes): %lf\n", reserve);
    }

    system("Pause");
    return(0);
}

最佳答案

您的某些 if 语句不起作用,例如,

if (决策2 == 1);{

if (决策3 == 1);{

它实际上的工作原理就像

if (decision2 == 1){
}

{
   // your code here

关于c - 铅电池实验室 - 普克特定律,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21387511/

相关文章:

c - 指针:为什么输出是 6?

C - 将非字母字符读取为字边界

c - 插入 AVL BST

c - 为什么我的 GTK+ 信号回调中出现段错误?

php - 好的编程软件

c - 为什么循环裂变在这种情况下有意义?

c - 如何 fork 一个 child 来替换已完成的 child ?

C 将方程结果字符串化

c - pthread_cancel() 没有取消线程,因为它应该

c - 在 C 中迭代实现 Euclid 算法