Ich versuche, eine einzelne Variable in C hinzuzufügen. Das Problem, das ich lösen muss, verlangt von mir, einen Benutzer zu fragen, wie oft X mit Y passiert ist. Einfaches Beispiel: Jedes Mal, wenn jemand Saft (x) trinkt, brauche ich die Menge an Saft (y) wiederholt hinzufügen. Das ist mein Programm bisher. Alles, was ich zu tun versuche, funktioniert nach meinem Wissen, abgesehen von dem letzten Code, den ich herausfinden muss, der vor der "if" -Anweisung stehen muss. Vielen Dank im voraus für Ihre Hilfe.Wie füge ich die selbe Variable zu sich selbst hinzu?
#include <stdio.h>
int main(){
int a=1;
int b=1;
int i;
float dollars;
float size;
float price;//per ounceprice
float wieght;
int drinks;//times roommate took some juice
int c=0;
int sips;
int total;
int totalowed;
int loopCounter;
int sipstotal;
//.06 per ounce
float juiceTaken;
float juiceTakenCost;
float juiceTakenTotal;
float costperounce=.06;
while(a=b){
printf("What is the weight (in oz.) of the original container of OJ?\n\n");
scanf("%f", &wieght);
printf("What is the cost of the original container of OJ in dollars?\n\n");
scanf("%f", &dollars);
price=dollars/wieght;
printf("%f\n\n", price);
printf("How many times did your roomate take your juice?\n\n");
scanf("%d", &drinks);
for(loopCounter = 0; loopCounter < drinks; loopCounter++){//repeat next line until loop equals amount of times roomate took juice
printf("How much juice did your roommate take this time?\n\n");
scanf("%d", &juiceTaken);
if(juiceTakenTotal>=10)
printf("Your roomate owes you $%.2f\n", juiceTakenTotal);
}
}
return 0;
}
Danke euch beiden! Sie haben beide eine Lösung bereitgestellt, die funktioniert hat! Ich habe ein anderes Problem mit dem Code gefunden, das es nicht funktionierte, als ich es anfing. In meiner scanf Zeile, wenn ich nach justTaken frage, notiere ich% d statt% f. Ich suche nach einem Gleitkommawert, während ich nach einem ganzzahligen Wert frage. lol, ich schätze deine Hilfe Jungs. –