Question

Modify the program pls so it then asks the user for another input making the program ask for a ye...

modify the program pls so it then asks the user for another input making the program ask for a yes or no question looping it codeblocks

#include <stdio.h>

#include <ctype.h>

#define NEWLINE '\n'

int main(void)

{

   /* Declare variables and function prototypes. */

   int k=0, formula[20], n, current=0, done=0, d1, d2;

   double error=0, weight, total=0;

   double atomic_wt(int atom);

   /* Read chemical formula from keyboard. */

   printf("Enter chemical formula for amino acid: \n");

   while ((formula[k]=getchar()) != NEWLINE)

      k++;

   n = k;

   /* Identify individual elements and add weights. */

   while (current<=(n-1) && done==0)

      {

      if (isalpha(formula[current]))

      {

         formula[current] = toupper(formula[current]);

         weight = atomic_wt(formula[current]);

         if (weight == 0)

            done = 1;

         else

         {

            if (current < n-1)

               d1 = isdigit(formula[current+1]);

            else

               d1 = 0;

            if (d1 && current<(n-2))

               d2 = isdigit(formula[current+2]);

            else

               d2 = 0;

            if (d1 && d2)

            {

               weight *= ((formula[current+1]-'0')*10 +

                          (formula[current+2]-'0'));

               current += 3;

            }

          else

               if (d1)

               {

                  weight *= (formula[current+1]-'0');

                  current += 2;

               }

               else

                  current++;

         }

         total += weight;

      }

      else

         done = 1;

    }

    /* Print formula and weight. */

    printf("Formula: \n");

    for (k=0; k<=n-1; k++)

       putchar(formula[k]);

    printf("\n");

    if (done == 0)

       printf("Molecular Weight: %f \n",total);

    else

       printf("Error in formula. \n");

    /* Exit program. */

    return 0;

}

/*--------------------------------------------------------------*/

/* This function returns the molecular weight of an element    */

/* in an amino acid.                                           */

double atomic_wt(int atom)

{

   /* Declare and initialize variables. */

   int k=0, element[5]={'H','C','N','O','S'};

   char choice;

   double m_wt[5]={1.00794,12.011,14.00674,

          15.9994,32.066}, weight;

   /* Search for element. */

   while (k<=4 && element[k]!=atom)

      k++;

   /* Return corresponding atomic weight. */

   if (k <= 4)

      weight = m_wt[k];

   else

      weight = 0;

   return weight;

   }

1 0
Add a comment Improve this question Transcribed image text
Answer #1

The line after "printf("Error in formula.\n");" and before "return 0;", type the following lines:

printf("Enter new formula:\n");

scanf( k,n, d1, d2, weight,atom);

Add a comment
Know the answer?
Add Answer to:
Modify the program pls so it then asks the user for another input making the program ask for a ye...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create another program that will prompt a user for input file. The user will choose from...

    Create another program that will prompt a user for input file. The user will choose from 4 choices: 1. Display all positive balance accounts. 2. Display all negative balance accounts. 3. Display all zero balance accounts. 4. End program. C PROGRAMMING my code so far #include<stdlib.h> #include<stdio.h> int main(void) { int request; int account; FILE *rptr; char name[20]; double balance; FILE *wptr;    int accountNumber;    if((wptr = fopen("clients.dat","w")) == NULL) { puts("File could not be opened"); } else {...

  • Please help me figure out why my code is not working properly.I had thought my logic...

    Please help me figure out why my code is not working properly.I had thought my logic was sound but later found it will run one time through fine however if the user opts to enter another value it will always be returned as an error. #include <iomanip> #include <iostream> #include <cstdlib> using namespace std; int const TRUE = 1; int const FALSE = 0; // declares functions void GetZipcode(); void RunAgain(); int GetSum(char d1, char d2, char d3, char d4,...

  • /*––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/ /*    */ /* */ /* This program computes average power, average magnitude */ /*...

    /*––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/ /*    */ /* */ /* This program computes average power, average magnitude */ /* and zero crossings from a speech signal. */ #include <stdio.h> #include <math.h> #define MAXIMUM 50 int main(void) { /* Declare variables */ int k=0, npts=30; double speech[MAXIMUM]={0.000000,-0.023438,-0.031250,-0.031250,-0.039063,-0.039063,-0.023438,0.000000,0.023438,0.070313,-0.039063,-0.039063,0.046875,0.101563,0.117188,0.101563,0.070313,0.054688,0.023438,0.000000,-0.031250,-0.039063,-0.070313,-0.070313,-0.070313,-0.070313,-0.062500,-0.046875,-0.039063,-0.031250}; /* Declare the function prototypes */    /* Compute and print statistics. */ printf("\n SPEECH DATA "); print(,,);//complete the statement printf("\n"); printf(" SPEECH STATISTICS : \n"); printf(" average power: %f \n",);//complete the statement printf(" average magnitude: %f...

  • Convert the C program into a C++ program.Replace all C input/output statements with C++ statements (cin,...

    Convert the C program into a C++ program.Replace all C input/output statements with C++ statements (cin, cout, cin.getline) . Re-make the func function by the following prototype: void func( double, double &); #include int user_interface(); double func(double); void print_table(); int main (int argc, char *argv[]) {    print_table(user_interface());    return 0 ; } int user_interface(int val){    int input = 0;    printf("This function takes in x and returns an output\n");    printf("Enter Maximum Number of X:");    scanf("%d", &input);...

  • Please help modify my C program to be able to answer these questions, it seems the...

    Please help modify my C program to be able to answer these questions, it seems the spacing and some functions arn't working as planeed. Please do NOT copy and paste other work as the answer, I need my source code to be modified. Source code: #include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> int main(void) { char title[50]; char col1[50]; char col2[50]; int point[50]; char names[50][50]; printf("Enter a title for the data:\n"); fgets (title, 50, stdin); printf("You entered: %s\n", title);...

  • How can I integrate these programs into this menu template: #define _CRT_SECURE_NO_WARNINGS #include #include #include #include...

    How can I integrate these programs into this menu template: #define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include void program_one (); void program_two (); void program_three (); void program_four(); void program_five(); int main() { int menu_option = 0; while (menu_option != 9) { printf(" = 1\n"); //Change this to your first program name. Nothing else. printf(" = 2\n"); //Change this to your second program name. Nothing else. printf(" = 3\n"); //Change this to your third program name. Nothing else. printf(" =...

  • Write a program that asks the user to type an even number or 111 to stop....

    Write a program that asks the user to type an even number or 111 to stop. When the user types an even number, display the message “Great Work”, and then ask for input again. When the user types an odd number, display the message “Try again” and ask the user to enter again. When the user enters the sentinel value of 111 the program ends I've attempted this but it went horribly wrong. we are only suppose to use while,...

  • Modify the program q1.c by adding calls to uthread_join (and making no other changes) so that...

    Modify the program q1.c by adding calls to uthread_join (and making no other changes) so that it always prints the lines “zero” to “three” in order; i.e., its output must always be the following. q1.c code as below: #include <stdlib.h> #include <stdio.h> #include "uthread.h" uthread_t t0, t1, t2; void randomStall() { int i, r = random() >> 16; while (i++<r); } void* p0(void* v) { randomStall(); printf("zero\n"); return NULL; } void* p1(void* v) { randomStall(); printf("one\n"); return NULL; } void*...

  • C Programming - RSA encryption Hi there, I'm struggling with writing a C program to encrypt and decrypt a string usi...

    C Programming - RSA encryption Hi there, I'm struggling with writing a C program to encrypt and decrypt a string using the RSA algorithm (C90 language only). It can contain ONLY the following libraries: stdio, stdlib, math and string. I want to use the following function prototypes to try and implement things: /*Check whether a given number is prime or not*/ int checkPrime(int n) /*to find gcd*/ int gcd(int a, int h) void Encrypt(); void Decrypt(); int getPublicKeys(); int getPrivateKeys();...

  • I am trying to write this code which asks "Write a program that ask the user,...

    I am trying to write this code which asks "Write a program that ask the user, the question: What is a^b? //The program generates two signed integers and gives the user four attempts to get the correct answer //a=- , b = + //a= + , b = - " So far this what I wrote. I am not sure how to do this correctly. #include<iostream> #include<cstdlib> #include<ctime> using namespace std; int main() {    srand(time(0));    int guess,a,ans,b, k;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT