Thread: combo for loops with if structures

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    9

    Unhappy combo for loops with if structures

    okay, i'm trying to make a for loop that will run from 1 to the number of records i've entered in a previous while loop
    then i'm making calculations based on the number of things they buy (more you buy, less unit cost) here's my code, my output is very confusing as it just lists a slew of numbers after each other, i don't know what the problem is, or where it is. help would be appreciated. here's what i got.

    the part incased in asterixes is where i'm running into problems, i don't know if you need the rest of the program for reference

    #include <stdio.h>

    int main()

    {int id_num[20];
    int num_chair[20];
    int num_sofa[20];
    int total_chair[20];
    int total_sofa[20];
    int total_both[20];
    int c,i,s;

    printf("Quantity\t Chair Price\t Sofa Price\n");
    printf("1-50\t\t $80\t\t $325\n");
    printf("51-100\t\t $65\t\t $260\n");
    printf("101-200\t\t $55\t\t $225\n");
    printf("over 200\t $50\t\t $190\n");


    {
    int x=1;

    printf("Enter <0> under ID number when finished\n");
    scanf("%d", &id_num[x]);

    while(id_num[x] != 0) {
    printf("Enter the amount of chairs you desire to order\n");
    scanf ("%d", &num_chair[x]);
    printf("Enter the amount of sofas you desire to order\n");
    scanf ("%d", &num_sofa[x]);
    x++;
    printf ("Enter <0> under ID number when finished\n");
    scanf("%d", &id_num[x]);
    }


    **************************************************
    for (c=1;c<x;c++){
    if (num_chair[c]<=50)
    total_chair[c]=num_chair[c]*80;
    else if (num_chair[c]<=100)
    total_chair[c]=num_chair[c]*65;
    else if (num_chair[c]<=200)
    total_chair[c]=num_chair[c]*55;
    else if (num_chair[c]>200)
    total_chair[c]=num_chair[c]*50;
    }

    for (s=1;s<x;s++){
    if (num_sofa[s]<=50)
    total_sofa[s]=num_sofa[s]*80;
    else if (num_sofa[s]<=100)
    total_sofa[s]=num_sofa[s]*65;
    else if (num_sofa[s]<=200)
    total_sofa[s]=num_sofa[s]*55;
    else if (num_sofa[s]>200)
    total_sofa[s]=num_sofa[s]*50;
    }


    for (i=1;i<x;i++)
    {
    printf ("%d",&id_num[i],"\n");
    printf ("%d",&num_chair[i],"\n");
    printf ("%d",&total_chair[i],"\n");
    "\n";
    }
    **********************************************
    }
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Your final printf statements are badly broken.

    Use these
    printf ("%d\n",id_num[i]);
    printf ("%d\n",num_chair[i]);
    printf ("%d\n",total_chair[i]);
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. Reset Combo Control VS C++ 6.0
    By WaterNut in forum Windows Programming
    Replies: 8
    Last Post: 12-26-2007, 10:37 AM
  3. Create new combo boxes based on items selected in preview combo box
    By RealityFusion in forum Windows Programming
    Replies: 2
    Last Post: 01-10-2007, 09:50 AM
  4. SkyLock tech demo (GUI - DX combo box)
    By jdinger in forum Game Programming
    Replies: 4
    Last Post: 07-14-2002, 09:04 PM
  5. Methods for Sorting Structures by Element...
    By Sebastiani in forum C Programming
    Replies: 9
    Last Post: 09-14-2001, 12:59 PM