Why does one method of adding all the elements of an array fail when similar methods succeed

Advertisements I have an array of doubles. To simplify the example, I use an array of length 3. I want to add all 3 elements of the array. I do it in 3 ways. Here’s the program to demonstrate. #include <stdio.h> int main() { double a[3] = {1.,3.,5.}; double sum1 = a[0]+a[1]+a[2]; int i=0; double… Read More Why does one method of adding all the elements of an array fail when similar methods succeed

How to add two numbers using Console.ReadLine()

Advertisements I want to add two numbers using Console.ReadLine(), but it gives me the error Invalid expression term ‘int’ Here is my code: using System; namespace MyApplication { class Program { static void Main(string[] args) { Console.WriteLine("Enter a number:"); string number1 = Console.ReadLine(); Console.WriteLine("Enter another number:"); string number2 = Console.ReadLine(); Console.WriteLine("The sum of those numbers… Read More How to add two numbers using Console.ReadLine()

Sum of value in a dictionary

Advertisements I’m new here. I wanted to sum all the values inside a dictionary, but my values are all strings, I don’t know how to convert the strings to integers… I really appreciate if anyone can help with it! Here’s the dictionary with code dic1 = dict() dic1 = {‘2012-03-06’:[‘1′,’4′,’5′],’2012-03-12’:[‘7′,’3′,’10’]} for i in dic1: print(i,’,’,sum(dic1[i]))… Read More Sum of value in a dictionary

I would like to make my program display the order total/invoice

Advertisements Here is what ive done: food =["cheeseburger", "smallchips", "drink"] prices =[2.50, 1.50, 1] x=0 myorderfood=[] myordercost=[] print("Burgers\n") print("Menu:") print("Cheeseburger. Cost – $2.50 each") print("Small chips. Cost – $1.50 each") print("Drink – Cola only. Cost – $1.00 each\n") I want to display an invoice at the end once the user has completed there order showing… Read More I would like to make my program display the order total/invoice