Writing a C Language Program~!?

I am the beginner in the Computer Science Courses and I get stuck on this lab =( If anyone can help me out, can you please make corrections on what I have done so far for me?

====================================================

#include<stdio.h>

int main()

{

float TV = 400.00;

float VCR = 220.00;

float REMOTE_CTRLR = 35.00;

float CD_PLAYER = 300.00;

float TAPE_RECORDER = 150.00;

float TAX = 0.0825;

int tv;

int vcr;

int rmtectrl;

int cdplayer;

int tpercdr;

float tvttl;

float vcrttl;

float rmtectrlttl;

float cdplayerttl;

float tpercdrttl;

float subtotal;

float tax;

float totalprice;

printf("How Many TVs Were Sold? ");

scanf_s("%d", &tv);

printf("How Many VCRs Were Sold? ");

scanf_s("%d", &vcr);

printf("How Many Remote Controllers Were Sold? ");

scanf_s("%d", &rmtectrl);

printf("How Many CDs Were Sold? ");

scanf_s("%d", &cdplayer);

printf("How Many Tape Recorders Were Sold? ");

scanf_s("%d", &tpercdr);

(float)tvttl = tv * TV;

(float)vcrttl = vcr * VCR;

(float)rmtectrlttl = rmtectrl * REMOTE_CTRLR;

(float)cdplayerttl = cdplayer * CD_PLAYER;

(float)tpercdrttl = tpercdr * TAPE_RECORDER;

subtotal = tvttl + vcrttl + rmtectrlttl + cdplayerttl + tpercdrttl;

tax = subtotal * TAX;

total = subtotal + tax;

printf("\n\n\tQTY\tDESCRIPTION\tUNIT PRICE\tTOTAL PRICE\n");

printf("\t---\t-----------\t----------\t-----------\n");

printf("\t%2d\tTV\t10.2f\tttvttl", tv, TV, tvttl\n);

printf("\t%2d\tVCR\t10.2f\tvcrttl", vcr, VCR, vcrttl\n);

printf("\t%2d\tREMOTE_CTRLR\t10.2f\trmtectrlttl", rmtectrl, REMOTE_CTRLR, rmtectrlttl\n);

printf("\t%2d\tCD_PLAYER\t10.2f\tcdplayerttl", cdplayer, CD_PLAYER, cdplayerttl\n);

printf("\t%2d\tTAPE_RECORDER\t10.2f\ttpercdrttl", tpercdr, TAPE_RECORDER, tpercdrttl\n);

return 0;

}

Update:

It obviously contains a LOT of erros =(

2 Answers

Relevance
  • Anonymous
    1 decade ago
    Favorite Answer

    Hm....

    First time, u must read error compiler log.

    See what happens.

    /*

    46: Undefined symbol 'total' in function main

    49: Unterminated string or character const

    50: Function call missing ) in function main

    50: Illegal character '\' (0x5c) in function

    51: Illegal character '\' (0x5c) in function

    51: Function call missing ) in function maain

    52: Unterminated string or character const

    53: Function call missing ) in function main

    53: Unterminated string or character const

    54: Unterminated string or character const

    */

    • Login to reply the answers
  • 1 decade ago

    Your code contained a lot of errors, but overall just a couple of syntax corrections.

    The first part that was incorrect was that total was not initialized so you have to add

    int total = subtotal + tax;

    then your formatting was kinda off here and you forgot to close what you want to print with some quotes " and your \n were in the incorrectly place they are always placed inside quotes. Here is what I fixed to make the program compile and output correctly(btw I changed your ttl to total it was bothering me lol)

    printf("\n\n\tQTY\tDESCRIPTION\tUNIT PRICE\tTOTAL PRICE\n");

    printf("\t---\t-----------\t----------\t-----------\n");

    printf("\t%2d\tTV\t\t%10.2f\t%10.2f\n", tv, TV, tvTotal);

    printf("\t%2d\tVCR\t\t%10.2f\t%10.2f\n", vcr, VCR, vcrTotal);

    printf("\t%2d\tREMOTE_CTRLR\t%10.2f\t%10.2f\n", rmtectrl, REMOTE_CTRLR, rmtectrlTotal);

    printf("\t%2d\tCD_PLAYER\t%10.2f\t%10.2f\n", cdplayer, CD_PLAYER, cdplayerTotal);

    printf("\t%2d\tTAPE_RECORDER\t%10.2f\t%10.2f", tpercdr, TAPE_RECORDER, tpercdrTotal);

    also remember to include a getch() or a system("Pause") unless your compiler doesn't need it.

    Overall hope this helps.

    • Login to reply the answers
Still have questions? Get your answers by asking now.