0
Ballpark challenge help
Im having difficulty getting the 4 inputs from the string i know i got to add and and sales tax but i dont think im doing it right to get the inputs int Nachos = 6, Pizza =6,Cheeseburger=10; int Water=4;int Coke= 5; int main() { int first,second,third,fourth; cin>>first>>second>>third>>fourth; int order; order = first+second+third+fourth; cout<<order;
5 odpowiedzi
0
Is there fixed inputs?
I don't think.. You need to take a line of string and split to words
Else you can read by cin also
Like
while( cin>>order ) {
...
}
it read all words in sequence and fail when no more input word
hope it helps...
0
Hi @Jayakrishna🇮🇳,
sorry for butting-in but how do you get : while(cin >> order) {blah blah} to work?
I've done similar with stringstream, but with "cin", it just waits for more and more input from the keyboard.
0
rodwynnejones
Am not tested that way for ints,.. I will going to do but there it need reading of strings so no need to bothered to check before answering because it works with character and strings.. waiting for op response.
It should be
while(!cin.fail()) {
I think, it works. I used it once. when above way failed
edit:
with int I have same doubt but its working fine. I tested just now. in fails that way in c but in c++ it works..
0
I thought i could try the while like you were saying but i couldnt get a output that i get is 0 any hints?
int order;
cin>> order;
while (cin>>order);{
}
cout<<order;
0
string order;
for(int i = 0; i < 4; i++){
cin >> order:
//put your if/else and your arithmetic in here.
}