Thread: adding problem

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    5

    adding problem

    Hi,
    i am new to cprogramming and i want to do this thing. all in all i have 2 problems



    1)how do you add answers?
    Code:
    A+B=ans1
    C+D=ans2
    ans1+ans2=ans3//i cant do this part

    2)Next problem is that i cant add switches is there something i am doing wrong?
    i wanted to add cases.

    Code:
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        int A,B,C;
        double total;
        int cash,product;
        double change;
        
        switch (product){
        case 1:
        printf("how many product A: \n");
        cin>>A;
        break;
        
        case 2:
        printf("how many product B: \n");
        cin>>B;
        break;
        
        case 3:
        printf("how many product C: \n");
        cin>>C;
        break;
        }
        
        total=(case 1*10)+(case 2*20)+(case 3*30);
        \\ unit price of product A is 10, product B is 20, product C is 30
        printf("total amout due is: %lf  \n", total);
        
        printf("enter amount paid by customer: \n");
        cin>>cash;
        
        
        do{
        change=total-cash;\\still not working
        printf("total change will be:    \n", change);
        }
        while(total>=cash);
        
    
    
        
            
        system("PAUSE");
        return EXIT_SUCCESS;
    }

  2. #2
    Registered User Kudose's Avatar
    Join Date
    Jun 2006
    Posts
    92
    Your right (rvalue) and left (lvalue) values are switched.

    Code:
    int ans1 = A + B;
    int ans2 = C + D;
    int ans3 = ans1 + ans2;
    The rvalue should be where you do your equations and the lvalue should be a place to store the result. Sorry, I don't have the technical terms to describe rvalue and lvalue.
    IDE + Complier: Code::Blocks w/ GCC
    PC: AMD Phenom x4 2.2Ghz w/ 8G RAM
    OSes: CentOS 6.2 x64 & Win 7 Ultimate x64

  3. #3
    Registered User Kudose's Avatar
    Join Date
    Jun 2006
    Posts
    92
    For your switch, you are testing for product which hasn't been assigned a value.
    IDE + Complier: Code::Blocks w/ GCC
    PC: AMD Phenom x4 2.2Ghz w/ 8G RAM
    OSes: CentOS 6.2 x64 & Win 7 Ultimate x64

  4. #4
    Registered User Kudose's Avatar
    Join Date
    Jun 2006
    Posts
    92
    Sorry for all the posts ... how are you learning C++? Your program is more mangled than any other I've ever seen.
    IDE + Complier: Code::Blocks w/ GCC
    PC: AMD Phenom x4 2.2Ghz w/ 8G RAM
    OSes: CentOS 6.2 x64 & Win 7 Ultimate x64

  5. #5
    Registered User
    Join Date
    Apr 2010
    Posts
    5
    i only put it that way so that it can be explained easily. for the switch this is my first time to encounter a problem where i should add the. sorry if it is all messed up.

  6. #6
    Registered User Kudose's Avatar
    Join Date
    Jun 2006
    Posts
    92
    It's perfectly fine that it's all messed up. It's a part of learning. How are you teaching yourself C++?
    IDE + Complier: Code::Blocks w/ GCC
    PC: AMD Phenom x4 2.2Ghz w/ 8G RAM
    OSes: CentOS 6.2 x64 & Win 7 Ultimate x64

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. adding strings hard problem...
    By qubit67 in forum C Programming
    Replies: 28
    Last Post: 04-22-2007, 02:02 AM
  2. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  3. What's problem of adding two binary number?
    By Mathsniper in forum C Programming
    Replies: 1
    Last Post: 01-12-2007, 06:12 AM
  4. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  5. Major Problem
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 02-19-2002, 01:06 PM

Tags for this Thread