Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The question is first take the number of test cases and take input that no of times from the user.. the input is contains 3 integer value (no of friends, rate of each burger, and the money in hand)
if the person have the right amount of money in hand then type yes,, else no;;
means weather he/she can buy burgers or not for their friends..
the problem is
when i do ss >> money;
it stores last integer of current line(the money in hand) and first integer of next line(no of friends).. why it just ignored the enter key...

What I have tried:

input
3 
10 5 60
100 10 10
20 10 10

expected output
YES
NO
NO

MAIN CODE : Here I have used input array of string type which will contain all the inputs of one line as a string

for(j = 0; j < test_cases; j++)
	{
	    stringstream ss;
	    ss << input[j];
	    ss >> no_of_friends;
	    ss << input[j];
	    ss >> each_burger;
	    ss << input[j];
	    ss >> money;
        ss << "";
	if(each_burger*no_of_friends<money)
	    cout<<"YES"<<endl;
	else
	    cout<<"NO"<<endl;
	}

Problematic line
ss << input[j];
ss >> money;

what money stores
60100
Posted
Updated 22-Oct-22 21:56pm
v2

1 solution

Try this:
C++
int testCases;
cin >> testCases;
for (int i = 0; i < testCases; ++i)
{
    int friends, rate, money;
    cin >> friends;
    cin >> rate;
    cin >> money;

// perform calculations here
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900