Question

In: Computer Science

Can someone tell me how to fix warning msg in my code of C ++? I...

Can someone tell me how to fix warning msg in my code of C ++?

I got run-time error for this question please help me asap!

Errors are:
In function 'void bfs(int, int)':
warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 for(int j = 0; j < adj[pppp].size(); j++){
                  ^
In function 'int main()':
warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 scanf("%d %d %d %d %d", &a, &q, &c, &N, &m);
                                            ^
warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 scanf("%d %d", &fir, &bbb);
                         ^

#include <iostream>

#include <stdio.h>

#include <vector>

#include <algorithm>

#include <queue>

int min(int n,int arr[]){

int m=arr[0];

for(int i=1;i<n;i++)

if(m>arr[i])

m=arr[i];

return m;

}

using namespace std;

const int Max_max = 404040;

const int INF = 1e7;

int sum[Max_max];

int a,q,c,N,m,fir;

vector<int> adj[Max_max];

void bfs(int money, int start_node){

bool hello[Max_max];

for(int i=0; i<=N; i++)

hello[i] = false;

queue<int> q;

q.push(start_node);

hello[start_node] = true;

int distance = 1;

do{

int size = q.size();

for(int i = 0; i < size; i++){

int pppp = q.front(); q.pop();

for(int j = 0; j < adj[pppp].size(); j++){ //error undeclared identifier 'ppp_city'

int next = adj[pppp][j];

if(hello[next])

continue;

sum[pppp] += money * distance;

hello[next] = true;

q.push(next);

}

}

distance++;

} while (q.size() > 0);

}

int main(){

scanf("%d %d %d %d %d", &a, &q, &c, &N, &m);

for(int i=0; i < m; i++){

int aaa, bbb;

scanf("%d %d", &fir, &bbb);

adj[aaa].push_back(bbb);

adj[bbb].push_back(aaa);

}

bfs(a,1);

bfs(q,2);

bfs(c,N);

int fin = INF;

for(int i = 1; i <= N; i++)

fin = min(fin, sum); //error no matching function to call min

printf("%d",fin);

return 0;

}

Solutions

Expert Solution

If you have any doubts, please give me comment...

#include <iostream>

#include <stdio.h>

#include <vector>

#include <algorithm>

#include <queue>

int min(int n, int arr[])

{

    int m = arr[0];

    for (int i = 1; i < n; i++)

        if (m > arr[i])

            m = arr[i];

    return m;

}

using namespace std;

const int Max_max = 404040;

const int INF = 1e7;

int sum[Max_max];

int a, q, c, N, m, fir;

vector<int> adj[Max_max];

void bfs(int money, int start_node)

{

    bool hello[Max_max];

    for (int i = 0; i <= N; i++)

        hello[i] = false;

    queue<int> q;

    q.push(start_node);

    hello[start_node] = true;

    int distance = 1;

    do

    {

        int size = q.size();

        for (int i = 0; i < size; i++)

        {

            int pppp = q.front();

            q.pop();

            for (size_t j = 0; j < adj[pppp].size(); j++)

            { //error undeclared identifier 'ppp_city'

                int next = adj[pppp][j];

                if (hello[next])

                    continue;

                sum[pppp] += money * distance;

                hello[next] = true;

                q.push(next);

            }

        }

        distance++;

    } while (q.size() > 0);

}

int main()

{

    int result = scanf("%d %d %d %d %d", &a, &q, &c, &N, &m);

    if(result!=5)

        printf("input error!\n");

    for (int i = 0; i < m; i++)

    {

        int aaa, bbb;

        result = scanf("%d %d", &fir, &bbb);

        adj[aaa].push_back(bbb);

        adj[bbb].push_back(aaa);

    }

    bfs(a, 1);

    bfs(q, 2);

    bfs(c, N);

    int fin = INF;

    for (int i = 1; i <= N; i++)

        fin = min(fin, sum); //error no matching function to call min

    printf("%d", fin);

    return 0;

}


Related Solutions

I was wondering is someone could tell me why my code isn't compiling - Java ------------------------------------------------------------------------------------------------------------...
I was wondering is someone could tell me why my code isn't compiling - Java ------------------------------------------------------------------------------------------------------------ class Robot{ int serialNumber; boolean flies,autonomous,teleoperated; public void setCapabilities(int serialNumber, boolean flies, boolean autonomous, boolean teleoperated){ this.serialNumber = serialNumber; this.flies = flies; this.autonomous = autonomous; this.teleoperated = teleoperated; } public int getSerialNumber(){ return this.serialNumber; } public boolean canFly(){ return this.flies; } public boolean isAutonomous(){ return this.autonomous; } public boolean isTeleoperated(){ return this.teleoperated; } public String getCapabilities(){ StringBuilder str = new StringBuilder(); if(this.flies){str.append("canFly");str.append(" ");} if(this.autonomous){str.append("autonomous");str.append("...
Can someone look into my code and tell me what do you think: Thats Palindrome; //class...
Can someone look into my code and tell me what do you think: Thats Palindrome; //class name Palindrome public class Palindrome {    public static void palindromeChecker(String... str) {        // takes string one by one        for (String s : str) {            // creates a stringbuilder for s            StringBuilder sb = new StringBuilder(s);            // reverses the sb            sb.reverse();            // checks if both...
I am getting 7 errors can someone fix and explain what I did wrong. My code...
I am getting 7 errors can someone fix and explain what I did wrong. My code is at the bottom. Welcome to the DeVry Bank Automated Teller Machine Check balance Make withdrawal Make deposit View account information View statement View bank information Exit          The result of choosing #1 will be the following:           Current balance is: $2439.45     The result of choosing #2 will be the following:           How much would you like to withdraw? $200.50      The...
I need to fix this code, and could you please tell me what was the problem...
I need to fix this code, and could you please tell me what was the problem options 1 and 9 don't work #include <stdio.h> #include <time.h> #include <stdlib.h> // generate a random integer between lower and upper values int GenerateRandomInt(int lower, int upper){     int num =(rand()% (upper - lower+1))+lower;     return num; } // use random numbers to set the values of the matrix void InitializeMatrix(int row, int column, int dimension, int mat[][dimension]){     for(int i =0; i<row; i++){...
Okay, can someone please tell me what I am doing wrong?? I will show the code...
Okay, can someone please tell me what I am doing wrong?? I will show the code I submitted for the assignment. However, according to my instructor I did it incorrectly but I am not understanding why. I will show the instructor's comment after providing my original code for the assignment. Thank you in advance. * * * * * HourlyTest Class * * * * * import java.util.Scanner; public class HourlyTest {    public static void main(String[] args)     {        ...
Can someone please tell me if these calculations are correct! I'm reviewing my notes, and my...
Can someone please tell me if these calculations are correct! I'm reviewing my notes, and my professor said to always multiply the lipids by 3 and then divide by 7 to get the total amount of cals of lipids per day... I'm not completely sure why you do that? Can someone explain. Why don't you just stop at 700 cals for lipids? 1. Calculate the number of calories and grams protein for the following TPN solution: D50W in 500cc 10%...
Can someone please tell me on how can I have a double and character as one...
Can someone please tell me on how can I have a double and character as one of the items on my list? Thanks! This is what I got so far and the values I am getting are all integers. #pragma once #include <iostream> class Node { public:    int data;    Node* next;       // self-referential    Node()    {        data = 0;        next = nullptr;    }    Node(int value)    {        data...
Python programming: can someone please fix my code to get it to work correctly? The program...
Python programming: can someone please fix my code to get it to work correctly? The program should print "car already started" if you try to start the car twice. And, should print "Car is already stopped" if you try to stop the car twice. Please add comments to explain why my code isn't working. Thanks! # Program goals: # To simulate a car game. Focus is to build the engine for this game. # When we run the program, it...
I have to complete a template for pathophysiology , can someone tell me the pathophysiology of...
I have to complete a template for pathophysiology , can someone tell me the pathophysiology of pain. This is for a pathophysiology class
can someone tell me if i am wrong on any of these???? THANKS In order to...
can someone tell me if i am wrong on any of these???? THANKS In order to be able to deliver an effective persuasive speech, you need to be able to detect fallacies in your own as well as others’ speeches. The following statements of reasoning are all examples of the following fallacies: Hasty generalization, mistaken cause, invalid analogy, red herring, Ad hominem, false dilemma, bandwagon or slippery slope. 1. __________bandwagon fallacy_______ I don’t see any reason to wear a helmet...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT